mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
🎨 支持多设备操作不同文档后云端同步合并 https://github.com/siyuan-note/siyuan/issues/5092
This commit is contained in:
parent
f3e0502a38
commit
770686f5c0
3 changed files with 7 additions and 8 deletions
|
|
@ -344,7 +344,7 @@ func DownloadBackup() (err error) {
|
||||||
localDirPath := Conf.Backup.GetSaveDir()
|
localDirPath := Conf.Backup.GetSaveDir()
|
||||||
util.PushEndlessProgress(Conf.Language(68))
|
util.PushEndlessProgress(Conf.Language(68))
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
fetchedFilesCount, transferSize, _, err := ossDownload(localDirPath, "backup", false, map[string]bool{}, map[string]bool{})
|
fetchedFilesCount, transferSize, _, err := ossDownload(localDirPath, "backup", false)
|
||||||
if nil == err {
|
if nil == err {
|
||||||
elapsed := time.Now().Sub(start).Seconds()
|
elapsed := time.Now().Sub(start).Seconds()
|
||||||
util.LogInfof("downloaded backup [fetchedFiles=%d, transferSize=%s] in [%.2fs]", fetchedFilesCount, humanize.Bytes(transferSize), elapsed)
|
util.LogInfof("downloaded backup [fetchedFiles=%d, transferSize=%s] in [%.2fs]", fetchedFilesCount, humanize.Bytes(transferSize), elapsed)
|
||||||
|
|
@ -364,7 +364,7 @@ func UploadBackup() (err error) {
|
||||||
util.PushEndlessProgress(Conf.Language(61))
|
util.PushEndlessProgress(Conf.Language(61))
|
||||||
util.LogInfof("uploading backup...")
|
util.LogInfof("uploading backup...")
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
wroteFiles, transferSize, err := ossUpload(true, localDirPath, "backup", "not exist", false, map[string]bool{}, map[string]bool{})
|
wroteFiles, transferSize, err := ossUpload(true, localDirPath, "backup", "not exist", false)
|
||||||
if nil == err {
|
if nil == err {
|
||||||
elapsed := time.Now().Sub(start).Seconds()
|
elapsed := time.Now().Sub(start).Seconds()
|
||||||
util.LogInfof("uploaded backup [wroteFiles=%d, transferSize=%s] in [%.2fs]", wroteFiles, humanize.Bytes(transferSize), elapsed)
|
util.LogInfof("uploaded backup [wroteFiles=%d, transferSize=%s] in [%.2fs]", wroteFiles, humanize.Bytes(transferSize), elapsed)
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ func listCloudSyncDirOSS() (dirs []map[string]interface{}, size int64, err error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ossDownload(localDirPath, cloudDirPath string, bootOrExit bool, removeList, upsertList map[string]bool) (fetchedFilesCount int, transferSize uint64, downloadedFiles map[string]bool, err error) {
|
func ossDownload(localDirPath, cloudDirPath string, bootOrExit bool) (fetchedFilesCount int, transferSize uint64, downloadedFiles map[string]bool, err error) {
|
||||||
if !gulu.File.IsExist(localDirPath) {
|
if !gulu.File.IsExist(localDirPath) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -340,7 +340,7 @@ func ossDownload0(localDirPath, cloudDirPath, fetch string, fetchedFiles *int, t
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, boot bool, removeList, upsertList map[string]bool) (wroteFiles int, transferSize uint64, err error) {
|
func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, boot bool) (wroteFiles int, transferSize uint64, err error) {
|
||||||
if !gulu.File.IsExist(localDirPath) {
|
if !gulu.File.IsExist(localDirPath) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,8 @@ func SyncData(boot, exit, byHand bool) {
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
writingDataLock.Lock()
|
writingDataLock.Lock()
|
||||||
var err error
|
var err error
|
||||||
var removeList, upsertList map[string]bool
|
|
||||||
// 将 data 变更同步到 sync
|
// 将 data 变更同步到 sync
|
||||||
if removeList, upsertList, err = workspaceData2SyncDir(); nil != err {
|
if _, _, err = workspaceData2SyncDir(); nil != err {
|
||||||
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
|
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
|
||||||
Conf.Sync.Stat = msg
|
Conf.Sync.Stat = msg
|
||||||
util.PushErrMsg(msg, 7000)
|
util.PushErrMsg(msg, 7000)
|
||||||
|
|
@ -246,7 +245,7 @@ func SyncData(boot, exit, byHand bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wroteFiles, transferSize, err := ossUpload(false, localSyncDirPath, "sync/"+Conf.Sync.CloudName, device, boot, removeList, upsertList)
|
wroteFiles, transferSize, err := ossUpload(false, localSyncDirPath, "sync/"+Conf.Sync.CloudName, device, boot)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
util.PushClearProgress()
|
util.PushClearProgress()
|
||||||
IncWorkspaceDataVer() // 上传失败的话提升本地版本,以备下次上传
|
IncWorkspaceDataVer() // 上传失败的话提升本地版本,以备下次上传
|
||||||
|
|
@ -329,7 +328,7 @@ func SyncData(boot, exit, byHand bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchedFilesCount, transferSize, downloadedFiles, err := ossDownload(localSyncDirPath, "sync/"+Conf.Sync.CloudName, boot || exit, removeList, upsertList)
|
fetchedFilesCount, transferSize, downloadedFiles, err := ossDownload(localSyncDirPath, "sync/"+Conf.Sync.CloudName, boot || exit)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
util.PushClearProgress()
|
util.PushClearProgress()
|
||||||
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
|
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue