Feat: handle aria2 download complete

This commit is contained in:
HFO4
2020-02-05 11:22:19 +08:00
parent fe8f1b1ef5
commit 8c7e3883ee
10 changed files with 536 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
package util
import (
"io"
"os"
"path/filepath"
)
@@ -28,3 +29,18 @@ func CreatNestedFile(path string) (*os.File, error) {
return os.Create(path)
}
// IsEmpty 返回给定目录是否为空目录
func IsEmpty(name string) (bool, error) {
f, err := os.Open(name)
if err != nil {
return false, err
}
defer f.Close()
_, err = f.Readdirnames(1) // Or f.Readdir(1)
if err == io.EOF {
return true, nil
}
return false, err // Either not empty or error, suits both cases
}