An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 支持多设备操作不同文档后云端同步合并 https://github.com/siyuan-note/siyuan/issues/5092
Liang Dinge05289a6ae31
diff --git a/kernel/model/osssync.go b/kernel/model/osssync.goindex fc89e2558e..81c0aa1dfa 100644--- a/kernel/model/osssync.go+++ b/kernel/model/osssync.go@@ -437,27 +437,29 @@ func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, boif nil != err {return}- indexPath := filepath.Join(util.TempDir, "sync", "index.json")+ tmpSyncDir := filepath.Join(util.TempDir, "sync")+ indexPath := filepath.Join(tmpSyncDir, "index.json")if err = os.WriteFile(indexPath, data, 0644); nil != err {return}var tmpFetchedFiles intvar tmpTransferSize uint64- err = ossDownload0(util.TempDir+"/sync", "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false)+ err = ossDownload0(tmpSyncDir, "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false)if nil != err {util.LogErrorf("download merge cloud file failed: %s", err)return}- metaPath := filepath.Join(util.TempDir, "/sync/"+pathJSON)- err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList)+ metaPath := filepath.Join(tmpSyncDir, pathJSON)+ var upsertFiles []string+ upsertFiles, err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList)if nil != err {util.LogErrorf("download merge cloud file failed: %s", err)return}// 增量索引- for upsertFile, _ := range downloadList {+ for _, upsertFile := range upsertFiles {if !strings.HasSuffix(upsertFile, ".sy") {continue}@@ -864,7 +866,6 @@ func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileListcloudChangedList[cloudFile] = true}- delete(unchanged, filepath.Join(localDirPath, "index.json")) // 同步偶尔报错 `The system cannot find the path specified.` https://github.com/siyuan-note/siyuan/issues/4942filepath.Walk(localDirPath, func(path string, info fs.FileInfo, err error) error {if localDirPath == path || info.IsDir() {return nil@@ -886,7 +887,7 @@ func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileListdownloadList = map[string]bool{}for cloudChanged, _ := range cloudChangedList {- if upsertList[cloudChanged] || removeList[cloudChanged] || excludes[cloudChanged] {+ if upsertList[cloudChanged] || removeList[cloudChanged] || excludes[cloudChanged] || "/"+pathJSON == cloudChanged || "/index.json" == cloudChanged {continue}downloadList[cloudChanged] = truediff --git a/kernel/model/sync.go b/kernel/model/sync.goindex 8b9ed024e1..9467dc26bb 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -338,7 +338,7 @@ func SyncData(boot, exit, byHand bool) {metaPath := filepath.Join(Conf.Sync.GetSaveDir(), pathJSON)indexPath := filepath.Join(util.TempDir, "sync", "index.json")- err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadedFiles)+ _, err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadedFiles)if nil != err {util.LogErrorf("upsert partially downloaded files to workspace data failed: %s", err)}@@ -515,7 +515,7 @@ func SetSyncMode(mode int) (err error) {var syncLock = sync.Mutex{}-func syncDirUpsertWorkspaceData(metaPath, indexPath string, downloadedFiles map[string]bool) (err error) {+func syncDirUpsertWorkspaceData(metaPath, indexPath string, downloadedFiles map[string]bool) (upsertFiles []string, err error) {start := time.Now()modified := map[string]bool{}@@ -525,7 +525,7 @@ func syncDirUpsertWorkspaceData(metaPath, indexPath string, downloadedFiles map[modified[file] = true}- decryptedDataDir, _, err := recoverSyncData(metaPath, indexPath, modified)+ decryptedDataDir, upsertFiles, err := recoverSyncData(metaPath, indexPath, modified)if nil != err {util.LogErrorf("decrypt data dir failed: %s", err)return