Skip to content

Commit

Permalink
🎨 Improve WebDAV data synchronization compatibility siyuan-note/siyua…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 16, 2024
1 parent 65a89c3 commit 899893f
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions cloud/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,6 @@ func (webdav *WebDAV) parseErr(err error) error {
}

func (webdav *WebDAV) mkdirAll(folder string) (err error) {
if 1 > cache.Metrics.KeysAdded() {
// 预热缓存
infos, _ := webdav.Client.ReadDir(path.Join(webdav.Dir, "siyuan", "repo", "objects"))
for _, info := range infos {
k := "webdav.dir." + path.Join(webdav.Dir, "siyuan", "repo", "objects", info.Name())
cache.Set(k, true, 1)
}
}

cacheKey := "webdav.dir." + folder
_, ok := cache.Get(cacheKey)
if ok {
Expand Down Expand Up @@ -463,12 +454,25 @@ func (webdav *WebDAV) mkdirAll(folder string) (err error) {
return
}

err = webdav.Client.MkdirAll(folder, 0755)
err = webdav.parseErr(err)
if nil != err {
logging.LogErrorf("mkdir [%s] failed: %s", folder, err)
} else {
cache.Set(cacheKey, true, 1)
paths := strings.Split(folder, "/")
sub := "/"
for _, e := range paths {
if e == "" {
continue
}
sub += e + "/"

if _, ok := cache.Get("webdav.dir." + sub); ok {
continue
}

err = webdav.Client.Mkdir(sub, 0755)
err = webdav.parseErr(err)
if nil != err {
logging.LogErrorf("mkdir [%s] failed: %s", folder, err)
} else {
cache.Set("webdav.dir."+sub, true, 1)
}
}
return
}

0 comments on commit 899893f

Please sign in to comment.