Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: 优化云端同步上传资源占用 https://github.com/siyuan-note/siyuan/issues/5093

Liang Dinga1d2ab5ff9be
diff --git a/kernel/model/osssync.go b/kernel/model/osssync.go
index baa3adf1c3..972d1d4d62 100644
--- a/kernel/model/osssync.go
+++ b/kernel/model/osssync.go
@@ -728,7 +728,7 @@ func localUpsertRemoveListOSS(localDirPath string, cloudFileList map[string]*Clo
func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileList map[string]*CloudIndex, removedSyncList, upsertedSyncList, excludes map[string]bool) (localUpserts, cloudRemoves []string, err error) {
localUpserts, cloudRemoves = []string{}, []string{}
- if err = genIncCloudIndex(localDirPath, &localFileList, removedSyncList, upsertedSyncList, excludes); nil != err {
+ if err = incCloudIndex(localDirPath, &localFileList, removedSyncList, upsertedSyncList, excludes); nil != err {
return
}
@@ -763,6 +763,32 @@ func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileList
}
return nil
})
+
+ // syncignore 变更以后 cloud 和 local index 不一致,需要重新补全 local index
+ for _, upsert := range localUpserts {
+ info, statErr := os.Stat(upsert)
+ if nil != statErr {
+ util.LogErrorf("stat file [%s] failed: %s", upsert, statErr)
+ err = statErr
+ return
+ }
+ hash, hashErr := util.GetEtag(upsert)
+ if nil != hashErr {
+ util.LogErrorf("get file [%s] hash failed: %s", upsert, hashErr)
+ err = hashErr
+ return
+ }
+ localFileList[filepath.ToSlash(strings.TrimPrefix(upsert, localDirPath))] = &CloudIndex{Hash: hash, Size: info.Size()}
+ }
+ data, err := gulu.JSON.MarshalJSON(localFileList)
+ if nil != err {
+ util.LogErrorf("marshal sync cloud index failed: %s", err)
+ return
+ }
+ if err = os.WriteFile(filepath.Join(localDirPath, "index.json"), data, 0644); nil != err {
+ util.LogErrorf("write sync cloud index failed: %s", err)
+ return
+ }
return
}
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index ef40a9b8d4..1c2842a251 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -665,8 +665,8 @@ func genFullCloudIndex(localDirPath string, excludes map[string]bool) (err error
return
}
-// genCloudIndex 增量生成云端索引文件。
-func genIncCloudIndex(localDirPath string, localFileList *map[string]*CloudIndex, removes, upserts, excludes map[string]bool) (err error) {
+// incCloudIndex 增量生成云端索引文件。
+func incCloudIndex(localDirPath string, localFileList *map[string]*CloudIndex, removes, upserts, excludes map[string]bool) (err error) {
for remove, _ := range removes {
delete(*localFileList, remove)
}
@@ -692,16 +692,6 @@ func genIncCloudIndex(localDirPath string, localFileList *map[string]*CloudIndex
}
(*localFileList)[upsert] = &CloudIndex{Hash: hash, Size: info.Size()}
}
-
- data, err := gulu.JSON.MarshalJSON(localFileList)
- if nil != err {
- util.LogErrorf("marshal sync cloud index failed: %s", err)
- return
- }
- if err = os.WriteFile(filepath.Join(localDirPath, "index.json"), data, 0644); nil != err {
- util.LogErrorf("write sync cloud index failed: %s", err)
- return
- }
return
}