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 Ding25990a53f8c9
diff --git a/kernel/model/osssync.go b/kernel/model/osssync.goindex aee98ffb56..9afab9b765 100644--- a/kernel/model/osssync.go+++ b/kernel/model/osssync.go@@ -320,7 +320,7 @@ func ossDownload0(localDirPath, cloudDirPath, fetch string, fetchedFiles *int, treturn}-func ossUpload(localDirPath, cloudDirPath, cloudDevice string, boot bool, removedSyncList, upsertedSyncList map[string]bool) (wroteFiles int, transferSize uint64, err error) {+func ossUpload(localDirPath, cloudDirPath, cloudDevice string, boot bool, removeList, upsertList map[string]bool) (wroteFiles int, transferSize uint64, err error) {if !gulu.File.IsExist(localDirPath) {return}@@ -328,16 +328,16 @@ func ossUpload(localDirPath, cloudDirPath, cloudDevice string, boot bool, removelocalDevice := Conf.System.IDexcludes := getSyncExcludedList(localDirPath)localFileList, genIndexErr := genCloudIndex(localDirPath, excludes)+ if nil != genIndexErr {+ err = genIndexErr+ return+ }+var localUpserts, cloudRemoves []stringvar cloudFileList map[string]*CloudIndexif "" != localDevice && localDevice == cloudDevice {//util.LogInfof("cloud device is the same as local device, get index from local")- if nil == genIndexErr {- localUpserts, cloudRemoves, err = cloudUpsertRemoveLocalListOSS(localDirPath, removedSyncList, upsertedSyncList, excludes)- } else {- util.LogInfof("get local index failed [%s], get index from cloud", err)- cloudFileList, err = getCloudFileListOSS(cloudDirPath)- }+ localUpserts, cloudRemoves, err = cloudUpsertRemoveLocalListOSS(localDirPath, removeList, upsertList, excludes)} else {cloudFileList, err = getCloudFileListOSS(cloudDirPath)}diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex 225f186eb1..2b951621f4 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -135,9 +135,9 @@ func SyncData(boot, exit, byHand bool) {WaitForWritingFiles()writingDataLock.Lock()var err error- var removedSyncList, upsertedSyncList map[string]bool+ var removeList, upsertList map[string]bool// 将 data 变更同步到 sync- if removedSyncList, upsertedSyncList, err = workspaceData2SyncDir(); nil != err {+ if removeList, upsertList, err = workspaceData2SyncDir(); nil != err {msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))Conf.Sync.Stat = msgutil.PushErrMsg(msg, 7000)@@ -246,7 +246,7 @@ func SyncData(boot, exit, byHand bool) {return}- wroteFiles, transferSize, err := ossUpload(localSyncDirPath, "sync/"+Conf.Sync.CloudName, device, boot, removedSyncList, upsertedSyncList)+ wroteFiles, transferSize, err := ossUpload(localSyncDirPath, "sync/"+Conf.Sync.CloudName, device, boot, removeList, upsertList)if nil != err {util.PushClearProgress()IncWorkspaceDataVer() // 上传失败的话提升本地版本,以备下次上传@@ -591,17 +591,17 @@ func syncDir2WorkspaceData(boot bool) (upsertFiles, removeFiles []string, err er// workspaceData2SyncDir 将 data 的数据更新到 sync 中。// 1. 删除 sync 中多余的文件// 2. 将 data 中新增/修改的文件加密后拷贝到 sync 中-func workspaceData2SyncDir() (removedSyncList, upsertedSyncList map[string]bool, err error) {+func workspaceData2SyncDir() (removeList, upsertList map[string]bool, err error) {start := time.Now()filesys.ReleaseAllFileLocks()passwd := Conf.E2EEPasswd- unchangedDataList, removedSyncList, err := calcUnchangedDataList(passwd)+ unchangedDataList, removeList, err := calcUnchangedDataList(passwd)if nil != err {return}- encryptedDataDir, upsertedSyncList, err := prepareSyncData(passwd, unchangedDataList)+ encryptedDataDir, upsertList, err := prepareSyncData(passwd, unchangedDataList)if nil != err {util.LogErrorf("encrypt data dir failed: %s", err)return@@ -758,7 +758,7 @@ func recoverSyncData(modified map[string]bool) (decryptedDataDir string, upsertFreturn}-func prepareSyncData(passwd string, unchangedDataList map[string]bool) (encryptedDataDir string, upsertedSyncList map[string]bool, err error) {+func prepareSyncData(passwd string, unchangedDataList map[string]bool) (encryptedDataDir string, upsertList map[string]bool, err error) {encryptedDataDir = filepath.Join(util.WorkspaceDir, "incremental", "sync-encrypt")if err = os.RemoveAll(encryptedDataDir); nil != err {return@@ -851,7 +851,7 @@ func prepareSyncData(passwd string, unchangedDataList map[string]bool) (encrypte}}- upsertedSyncList = map[string]bool{}+ upsertList = map[string]bool{}// 检查文件是否全部已经编入索引err = filepath.Walk(encryptedDataDir, func(path string, info fs.FileInfo, _ error) error {if encryptedDataDir == path {@@ -866,7 +866,7 @@ func prepareSyncData(passwd string, unchangedDataList map[string]bool) (encrypte}if !info.IsDir() {- upsertedSyncList["/"+path] = true+ upsertList["/"+path] = true}return nil})@@ -984,8 +984,8 @@ func calcUnchangedSyncList() (ret map[string]bool, removes []string, err error)return}-// calcUnchangedDataList 计算 sync 和 data 一致(没有修改过)的文件列表 unchangedDataList,并删除 sync 中不存在于 data 中的多余文件 removedSyncList。-func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, removedSyncList map[string]bool, err error) {+// calcUnchangedDataList 计算 sync 和 data 一致(没有修改过)的文件列表 unchangedDataList,并删除 sync 中不存在于 data 中的多余文件 removeList。+func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, removeList map[string]bool, err error) {syncDir := Conf.Sync.GetSaveDir()meta := filepath.Join(syncDir, pathJSON)if !gulu.File.IsExist(meta) {@@ -1007,7 +1007,7 @@ func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, re}unchangedDataList = map[string]bool{}- removedSyncList = map[string]bool{}+ removeList = map[string]bool{}filepath.Walk(syncDir, func(path string, info fs.FileInfo, _ error) error {if syncDir == path || pathJSON == info.Name() {return nil@@ -1017,7 +1017,7 @@ func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, reencryptedP = filepath.ToSlash(encryptedP)decryptedP := metaJSON[encryptedP]if "" == decryptedP { // 理论上不会发生- removedSyncList[path] = true+ removeList[path] = trueif gulu.File.IsDir(path) {return filepath.SkipDir}@@ -1026,7 +1026,7 @@ func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, redataP := filepath.Join(util.DataDir, decryptedP)dataP = filepath.FromSlash(dataP)if !gulu.File.IsExist(dataP) { // data 已经删除的文件- removedSyncList[path] = true+ removeList[path] = trueif gulu.File.IsDir(path) {return filepath.SkipDir}@@ -1044,7 +1044,7 @@ func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, retmp := map[string]bool{}// 在 sync 中删除 data 中已经删除的文件- for remove, _ := range removedSyncList {+ for remove, _ := range removeList {if strings.HasSuffix(remove, "index.json") {continue}@@ -1057,7 +1057,7 @@ func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, reutil.LogErrorf("remove [%s] failed: %s", remove, err)}}- removedSyncList = tmp+ removeList = tmpreturn}