|
@ -3,6 +3,7 @@ package common |
|
|
import ( |
|
|
import ( |
|
|
"bufio" |
|
|
"bufio" |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"io" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"os" |
|
|
"os" |
|
|
"os/signal" |
|
|
"os/signal" |
|
@ -44,6 +45,20 @@ func EnsureDir(dir string, mode os.FileMode) error { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func IsDirEmpty(name string) (bool, error) { |
|
|
|
|
|
f, err := os.Open(name) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return true, err //folder is non-existent
|
|
|
|
|
|
} |
|
|
|
|
|
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
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func FileExists(filePath string) bool { |
|
|
func FileExists(filePath string) bool { |
|
|
_, err := os.Stat(filePath) |
|
|
_, err := os.Stat(filePath) |
|
|
return !os.IsNotExist(err) |
|
|
return !os.IsNotExist(err) |
|
|