From 899893f6ae97d9c2e8509d50bdd8ae8d058b2e52 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 16 Nov 2024 16:54:10 +0800 Subject: [PATCH] :art: Improve WebDAV data synchronization compatibility https://github.com/siyuan-note/siyuan/issues/12961 --- cloud/webdav.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/cloud/webdav.go b/cloud/webdav.go index 5d0c40c..f155cb6 100644 --- a/cloud/webdav.go +++ b/cloud/webdav.go @@ -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 { @@ -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 }