From e8351aab047ed459f30ff1986fc4caff66452f4a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 6 Jun 2022 13:44:54 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BA=91=E7=AB=AF?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=8A=E4=BC=A0=E8=B5=84=E6=BA=90=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E5=92=8C=E8=80=97=E6=97=B6=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/5093?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/osssync.go | 22 +++++++++++++++++++--- kernel/model/sync.go | 13 ++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/kernel/model/osssync.go b/kernel/model/osssync.go index 16381198d..c83477cb2 100644 --- a/kernel/model/osssync.go +++ b/kernel/model/osssync.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "io" "io/fs" "os" "path" @@ -801,10 +802,21 @@ func localUpsertRemoveListOSS(localDirPath string, cloudFileList map[string]*Clo return nil } - localModTime := info.ModTime().Unix() - if cloudIdx.Updated == localModTime { + // TODO: 优化云端同步上传资源占用和耗时 https://github.com/siyuan-note/siyuan/issues/5093 + localHash, hashErr := util.GetEtag(path) + if nil != hashErr { + err = hashErr + return io.EOF + } + + if cloudIdx.Hash == localHash { unchanged[relPath] = true } + + //localModTime := info.ModTime().Unix() + //if cloudIdx.Updated == localModTime { + // unchanged[relPath] = true + //} return nil }) @@ -859,10 +871,14 @@ func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileList cloudRemoves = append(cloudRemoves, cloudFile) continue } - if localIdx.Updated == cloudIdx.Updated { + if localIdx.Hash == cloudIdx.Hash { unchanged[filepath.Join(localDirPath, cloudFile)] = true continue } + //if localIdx.Updated == cloudIdx.Updated { + // unchanged[filepath.Join(localDirPath, cloudFile)] = true + // continue + //} cloudChangedList[cloudFile] = true } diff --git a/kernel/model/sync.go b/kernel/model/sync.go index 9467dc26b..811107ec4 100644 --- a/kernel/model/sync.go +++ b/kernel/model/sync.go @@ -607,8 +607,9 @@ func workspaceData2SyncDir() (removeList, upsertList map[string]bool, err error) } type CloudIndex struct { - Size int64 `json:"size"` - Updated int64 `json:"updated"` // Unix timestamp 秒 + Hash string `json:"hash"` + Size int64 `json:"size"` + Updated int64 `json:"updated"` // Unix timestamp 秒 } // genCloudIndex 生成云端索引文件。 @@ -628,7 +629,13 @@ func genCloudIndex(localDirPath string, excludes map[string]bool) (cloudIndex ma p := strings.TrimPrefix(path, localDirPath) p = filepath.ToSlash(p) - cloudIndex[p] = &CloudIndex{Size: info.Size(), Updated: info.ModTime().Unix()} + // TODO: 优化云端同步上传资源占用和耗时 https://github.com/siyuan-note/siyuan/issues/5093 + hash, hashErr := util.GetEtag(path) + if nil != hashErr { + err = hashErr + return io.EOF + } + cloudIndex[p] = &CloudIndex{Hash: hash, Size: info.Size(), Updated: info.ModTime().Unix()} return nil }) if nil != err {