From d00ef7d2e43c2d95bed5b5a97dbc67689d7e6d61 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 5 Jun 2022 23:01:40 +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 | 198 ++++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 100 deletions(-) diff --git a/kernel/model/osssync.go b/kernel/model/osssync.go index cd28277d4..3e5d7da71 100644 --- a/kernel/model/osssync.go +++ b/kernel/model/osssync.go @@ -33,8 +33,6 @@ 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" ) @@ -186,60 +184,60 @@ func ossDownload(isBackup bool, localDirPath, cloudDirPath string, bootOrExit bo if !isBackup && (0 < len(removeList) || 0 < len(upsertList)) { // 上传合并本地变更 - var removed, upserted bool - var removes []string - for remove, _ := range removeList { - removes = append(removes, remove) - } - removeErr := ossRemove0(cloudDirPath, removes) - if nil != removeErr { - util.LogErrorf("remove merge cloud file failed: %s", removeErr) - } else { - for remove, _ := range removeList { - delete(cloudFileList, remove) - } - removed = 0 < len(removeList) - } - - var tmpWroteFiles int - var tmpTransferSize uint64 - for upsert, _ := range upsertList { - localUpsert := filepath.Join(localDirPath, upsert) - info, statErr := os.Stat(localUpsert) - if nil != statErr { - util.LogErrorf("stat file [%s] failed: %s", localUpsert, statErr) - upserted = false - break - } - - if uploadErr := ossUpload0(localDirPath, cloudDirPath, localUpsert, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr { - util.LogErrorf("upload merge cloud file [%s] failed: %s", upsert, uploadErr) - upserted = false - break - } - cloudFileList[upsert] = &CloudIndex{ - Size: info.Size(), - Updated: info.ModTime().Unix(), - } - upserted = true - } - - if removed || upserted { - data, marshalErr := gulu.JSON.MarshalJSON(cloudFileList) - if nil != marshalErr { - util.LogErrorf("marshal cloud file list failed: %s", marshalErr) - } else { - tmpMergeDir := filepath.Join(util.TempDir, "sync") - tmpIndex := filepath.Join(tmpMergeDir, "index.json") - if writeErr := os.WriteFile(tmpIndex, data, 0644); nil != writeErr { - util.LogErrorf("write cloud file list failed: %s", writeErr) - } else { - if uploadErr := ossUpload0(tmpMergeDir, cloudDirPath, tmpIndex, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr { - util.LogErrorf("upload merge cloud file [%s] failed: %s", tmpIndex, uploadErr) - } - } - } - } + //var removed, upserted bool + //var removes []string + //for remove, _ := range removeList { + // removes = append(removes, remove) + //} + //removeErr := ossRemove0(cloudDirPath, removes) + //if nil != removeErr { + // util.LogErrorf("remove merge cloud file failed: %s", removeErr) + //} else { + // for remove, _ := range removeList { + // delete(cloudFileList, remove) + // } + // removed = 0 < len(removeList) + //} + // + //var tmpWroteFiles int + //var tmpTransferSize uint64 + //for upsert, _ := range upsertList { + // localUpsert := filepath.Join(localDirPath, upsert) + // info, statErr := os.Stat(localUpsert) + // if nil != statErr { + // util.LogErrorf("stat file [%s] failed: %s", localUpsert, statErr) + // upserted = false + // break + // } + // + // if uploadErr := ossUpload0(localDirPath, cloudDirPath, localUpsert, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr { + // util.LogErrorf("upload merge cloud file [%s] failed: %s", upsert, uploadErr) + // upserted = false + // break + // } + // cloudFileList[upsert] = &CloudIndex{ + // Size: info.Size(), + // Updated: info.ModTime().Unix(), + // } + // upserted = true + //} + // + //if removed || upserted { + // data, marshalErr := gulu.JSON.MarshalJSON(cloudFileList) + // if nil != marshalErr { + // util.LogErrorf("marshal cloud file list failed: %s", marshalErr) + // } else { + // tmpMergeDir := filepath.Join(util.TempDir, "sync") + // tmpIndex := filepath.Join(tmpMergeDir, "index.json") + // if writeErr := os.WriteFile(tmpIndex, data, 0644); nil != writeErr { + // util.LogErrorf("write cloud file list failed: %s", writeErr) + // } else { + // if uploadErr := ossUpload0(tmpMergeDir, cloudDirPath, tmpIndex, &tmpWroteFiles, &tmpTransferSize); nil != uploadErr { + // util.LogErrorf("upload merge cloud file [%s] failed: %s", tmpIndex, uploadErr) + // } + // } + // } + //} } localRemoves, cloudFetches, err := localUpsertRemoveListOSS(localDirPath, cloudFileList) @@ -429,50 +427,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 + //} } }