mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 09:30:48 +08:00
🎨 支持多设备操作不同文档后云端同步合并 https://github.com/siyuan-note/siyuan/issues/5092
This commit is contained in:
parent
8f42447a02
commit
ce04cfcc7a
@ -178,7 +178,8 @@ func ossDownload(isBackup bool, localDirPath, cloudDirPath string, bootOrExit bo
|
|||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmpIndex := filepath.Join(util.TempDir, "sync", "index.json")
|
tmpSyncDir := filepath.Join(util.TempDir, "sync")
|
||||||
|
tmpIndex := filepath.Join(tmpSyncDir, "index.json")
|
||||||
if err = os.WriteFile(tmpIndex, data, 0644); nil != err {
|
if err = os.WriteFile(tmpIndex, data, 0644); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -186,60 +187,58 @@ func ossDownload(isBackup bool, localDirPath, cloudDirPath string, bootOrExit bo
|
|||||||
if !isBackup && (0 < len(removeList) || 0 < len(upsertList)) {
|
if !isBackup && (0 < len(removeList) || 0 < len(upsertList)) {
|
||||||
// 上传合并本地变更
|
// 上传合并本地变更
|
||||||
|
|
||||||
//var removed, upserted bool
|
var removed, upserted bool
|
||||||
//var removes []string
|
var removes []string
|
||||||
//for remove, _ := range removeList {
|
for remove, _ := range removeList {
|
||||||
// removes = append(removes, remove)
|
removes = append(removes, remove)
|
||||||
//}
|
}
|
||||||
//removeErr := ossRemove0(cloudDirPath, removes)
|
err = ossRemove0(cloudDirPath, removes)
|
||||||
//if nil != removeErr {
|
if nil != err {
|
||||||
// util.LogErrorf("remove merge cloud file failed: %s", removeErr)
|
util.LogErrorf("remove merge cloud file failed: %s", err)
|
||||||
//} else {
|
return
|
||||||
// for remove, _ := range removeList {
|
}
|
||||||
// delete(cloudFileList, remove)
|
for remove, _ := range removeList {
|
||||||
// }
|
delete(cloudFileList, remove)
|
||||||
// removed = 0 < len(removeList)
|
}
|
||||||
//}
|
removed = 0 < len(removeList)
|
||||||
//
|
|
||||||
//var tmpWroteFiles int
|
var tmpWroteFiles int
|
||||||
//var tmpTransferSize uint64
|
var tmpTransferSize uint64
|
||||||
//for upsert, _ := range upsertList {
|
for upsert, _ := range upsertList {
|
||||||
// localUpsert := filepath.Join(localDirPath, upsert)
|
localUpsert := filepath.Join(localDirPath, upsert)
|
||||||
// info, statErr := os.Stat(localUpsert)
|
var info os.FileInfo
|
||||||
// if nil != statErr {
|
info, err = os.Stat(localUpsert)
|
||||||
// util.LogErrorf("stat file [%s] failed: %s", localUpsert, statErr)
|
if nil != err {
|
||||||
// upserted = false
|
util.LogErrorf("stat file [%s] failed: %s", localUpsert, err)
|
||||||
// break
|
return
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if uploadErr := ossUpload0(localDirPath, cloudDirPath, localUpsert, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr {
|
if err = ossUpload0(localDirPath, cloudDirPath, localUpsert, &tmpWroteFiles, &tmpTransferSize); nil != err {
|
||||||
// util.LogErrorf("upload merge cloud file [%s] failed: %s", upsert, uploadErr)
|
util.LogErrorf("upload merge cloud file [%s] failed: %s", upsert, err)
|
||||||
// upserted = false
|
return
|
||||||
// break
|
}
|
||||||
// }
|
cloudFileList[upsert] = &CloudIndex{
|
||||||
// cloudFileList[upsert] = &CloudIndex{
|
Size: info.Size(),
|
||||||
// Size: info.Size(),
|
Updated: info.ModTime().Unix(),
|
||||||
// Updated: info.ModTime().Unix(),
|
}
|
||||||
// }
|
upserted = true
|
||||||
// upserted = true
|
}
|
||||||
//}
|
|
||||||
//
|
if removed || upserted {
|
||||||
//if removed || upserted {
|
data, err = gulu.JSON.MarshalJSON(cloudFileList)
|
||||||
// data, marshalErr := gulu.JSON.MarshalJSON(cloudFileList)
|
if nil != err {
|
||||||
// if nil != marshalErr {
|
util.LogErrorf("marshal cloud file list failed: %s", err)
|
||||||
// util.LogErrorf("marshal cloud file list failed: %s", marshalErr)
|
return
|
||||||
// } else {
|
}
|
||||||
// tmpMergeDir := filepath.Join(util.TempDir, "sync")
|
if err = os.WriteFile(tmpIndex, data, 0644); nil != err {
|
||||||
// tmpIndex := filepath.Join(tmpMergeDir, "index.json")
|
util.LogErrorf("write cloud file list failed: %s", err)
|
||||||
// if writeErr := os.WriteFile(tmpIndex, data, 0644); nil != writeErr {
|
return
|
||||||
// util.LogErrorf("write cloud file list failed: %s", writeErr)
|
}
|
||||||
// } else {
|
if err = ossUpload0(tmpSyncDir, cloudDirPath, tmpIndex, &tmpWroteFiles, &tmpTransferSize); nil != err {
|
||||||
// if uploadErr := ossUpload0(tmpMergeDir, cloudDirPath, tmpIndex, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr {
|
util.LogErrorf("upload merge cloud file [%s] failed: %s", tmpIndex, err)
|
||||||
// util.LogErrorf("upload merge cloud file [%s] failed: %s", tmpIndex, uploadErr)
|
return
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
localRemoves, cloudFetches, err := localUpsertRemoveListOSS(localDirPath, cloudFileList)
|
localRemoves, cloudFetches, err := localUpsertRemoveListOSS(localDirPath, cloudFileList)
|
||||||
@ -448,13 +447,15 @@ func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, bo
|
|||||||
err = ossDownload0(util.TempDir+"/sync", "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false)
|
err = ossDownload0(util.TempDir+"/sync", "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
util.LogErrorf("download merge cloud file failed: %s", err)
|
util.LogErrorf("download merge cloud file failed: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
metaPath := filepath.Join(util.TempDir, "/sync/"+pathJSON)
|
metaPath := filepath.Join(util.TempDir, "/sync/"+pathJSON)
|
||||||
mergeErr := syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList)
|
err = syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList)
|
||||||
if nil != mergeErr {
|
if nil != err {
|
||||||
util.LogErrorf("download merge cloud file failed: %s", mergeErr)
|
util.LogErrorf("download merge cloud file failed: %s", err)
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
// 增量索引
|
// 增量索引
|
||||||
for upsertFile, _ := range downloadList {
|
for upsertFile, _ := range downloadList {
|
||||||
if !strings.HasSuffix(upsertFile, ".sy") {
|
if !strings.HasSuffix(upsertFile, ".sy") {
|
||||||
@ -471,10 +472,9 @@ func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, bo
|
|||||||
treenode.ReindexBlockTree(tree)
|
treenode.ReindexBlockTree(tree)
|
||||||
sql.UpsertTreeQueue(tree)
|
sql.UpsertTreeQueue(tree)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 重新生成云端索引
|
// 重新生成云端索引
|
||||||
if _, idxErr := genCloudIndex(localDirPath, excludes); nil != idxErr {
|
if _, err = genCloudIndex(localDirPath, excludes); nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user