From 8f42447a023d3de622d4ad8f6e9f1c5a957174fe Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 6 Jun 2022 10:52:38 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=A4=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=93=8D=E4=BD=9C=E4=B8=8D=E5=90=8C=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=90=8E=E4=BA=91=E7=AB=AF=E5=90=8C=E6=AD=A5=E5=90=88=E5=B9=B6?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/5092?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/osssync.go | 90 +++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/kernel/model/osssync.go b/kernel/model/osssync.go index 6352be4aa..43a4caac1 100644 --- a/kernel/model/osssync.go +++ b/kernel/model/osssync.go @@ -33,6 +33,8 @@ import ( "github.com/88250/gulu" "github.com/panjf2000/ants/v2" "github.com/qiniu/go-sdk/v7/storage" + "github.com/siyuan-note/siyuan/kernel/sql" + "github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/util" ) @@ -431,50 +433,50 @@ func ossUpload(isBackup bool, localDirPath, cloudDirPath, cloudDevice string, bo if 0 < len(downloadList) && !isBackup { // 下载合并云端变更 - //var data []byte - //data, err = gulu.JSON.MarshalJSON(cloudFileList) - //if nil != err { - // return - //} - //indexPath := filepath.Join(util.TempDir, "sync", "index.json") - //if err = os.WriteFile(indexPath, data, 0644); nil != err { - // return - //} - // - //var tmpFetchedFiles int - //var tmpTransferSize uint64 - //err = ossDownload0(util.TempDir+"/sync", "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false) - //if nil != err { - // util.LogErrorf("download merge cloud file failed: %s", err) - //} - // - //metaPath := filepath.Join(util.TempDir, "/sync/"+pathJSON) - //mergeErr := syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList) - //if nil != mergeErr { - // util.LogErrorf("download merge cloud file failed: %s", mergeErr) - //} else { - // // 增量索引 - // for upsertFile, _ := range downloadList { - // if !strings.HasSuffix(upsertFile, ".sy") { - // continue - // } - // - // upsertFile = filepath.ToSlash(upsertFile) - // box := upsertFile[:strings.Index(upsertFile, "/")] - // p := strings.TrimPrefix(upsertFile, box) - // tree, err0 := LoadTree(box, p) - // if nil != err0 { - // continue - // } - // treenode.ReindexBlockTree(tree) - // sql.UpsertTreeQueue(tree) - // } - //} - // - //// 重新生成云端索引 - //if _, idxErr := genCloudIndex(localDirPath, excludes); nil != idxErr { - // return - //} + var data []byte + data, err = gulu.JSON.MarshalJSON(cloudFileList) + if nil != err { + return + } + indexPath := filepath.Join(util.TempDir, "sync", "index.json") + if err = os.WriteFile(indexPath, data, 0644); nil != err { + return + } + + var tmpFetchedFiles int + var tmpTransferSize uint64 + err = ossDownload0(util.TempDir+"/sync", "sync/"+Conf.Sync.CloudName, "/"+pathJSON, &tmpFetchedFiles, &tmpTransferSize, false) + if nil != err { + util.LogErrorf("download merge cloud file failed: %s", err) + } + + metaPath := filepath.Join(util.TempDir, "/sync/"+pathJSON) + mergeErr := syncDirUpsertWorkspaceData(metaPath, indexPath, downloadList) + if nil != mergeErr { + util.LogErrorf("download merge cloud file failed: %s", mergeErr) + } else { + // 增量索引 + for upsertFile, _ := range downloadList { + if !strings.HasSuffix(upsertFile, ".sy") { + continue + } + + upsertFile = filepath.ToSlash(upsertFile) + box := upsertFile[:strings.Index(upsertFile, "/")] + p := strings.TrimPrefix(upsertFile, box) + tree, err0 := LoadTree(box, p) + if nil != err0 { + continue + } + treenode.ReindexBlockTree(tree) + sql.UpsertTreeQueue(tree) + } + } + + // 重新生成云端索引 + if _, idxErr := genCloudIndex(localDirPath, excludes); nil != idxErr { + return + } } }