-
Notifications
You must be signed in to change notification settings - Fork 9
/
root.go
47 lines (43 loc) · 902 Bytes
/
root.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
package putiosync
import (
"context"
"os"
"github.com/putdotio/go-putio"
"github.com/syncthing/syncthing/lib/fs"
)
const remoteFolderName = "putio-sync"
func ensureRoots(baseCtx context.Context) error {
var err error
localPath, err = fs.ExpandTilde(cfg.LocalDir)
if err != nil {
return err
}
err = os.MkdirAll(localPath, 0777)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(baseCtx, defaultTimeout)
defer cancel()
folders, _, err := client.Files.List(ctx, 0)
if err != nil {
return err
}
found := false
var f putio.File
for _, f = range folders {
if f.IsDir() && f.Name == remoteFolderName {
found = true
break
}
}
if !found {
ctx, cancel = context.WithTimeout(baseCtx, defaultTimeout)
defer cancel()
f, err = client.Files.CreateFolder(ctx, remoteFolderName, 0)
if err != nil {
return err
}
}
remoteFolderID = f.ID
return nil
}