-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfile.go
51 lines (40 loc) · 897 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package smugmug
import (
"errors"
"fmt"
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
)
func createFolder(path string) error {
_, err := os.Stat(path)
// Folder exists
if err == nil {
return nil
}
log.Infof("Creating folder %s\n", path)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return fmt.Errorf("cannot create folder: %v", err)
}
return nil
}
func checkDestFolder(folderPath string) error {
if !filepath.IsAbs(folderPath) {
return errors.New("destination path must be an absolute path")
}
info, err := os.Stat(folderPath)
if err != nil {
return errors.New("destination path doesn't exist")
}
if !info.IsDir() {
return errors.New("destination path isn't a directory")
}
return nil
}
func sameFileSizes(path string, fileSize int64) bool {
fi, err := os.Stat(path)
if err != nil {
log.Fatal(err)
}
return fi.Size() == fileSize
}