forked from aleskandro/nextcloud-kobo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
36 lines (32 loc) · 878 Bytes
/
utils.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
package pkg
import (
"log"
"os"
"path"
"time"
)
func shouldDownloadFile(localFilePath string, remoteModTime time.Time, size int64) bool {
info, err := os.Stat(localFilePath)
log.Println("Checking existence of ", localFilePath)
return err != nil || info.Size() != size || remoteModTime.After(info.ModTime())
}
func removeRemotelyDeletedFiles(localFileMap map[string]string, localPath string) (err error) {
files, _ := os.ReadDir(localPath)
for _, file := range files {
localFilePath := path.Join(localPath, file.Name())
if _, ok := localFileMap[localFilePath]; !ok {
log.Println("Removing file", file.Name(), localFilePath)
err = os.RemoveAll(localFilePath)
if err != nil {
return
}
}
}
return
}
func ensureDirExists(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return os.MkdirAll(dir, os.ModePerm)
}
return nil
}