🐛 清理资源文件后再次上传相同文件异常 Fix https://github.com/siyuan-note/siyuan/issues/6260

This commit is contained in:
Liang Ding 2022-10-18 22:36:20 +08:00
parent 4e7c898273
commit 4e2d8b7798
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 25 additions and 5 deletions

View file

@ -405,15 +405,21 @@ func RemoveUnusedAssets() (ret []string) {
return
}
var hashes []string
for _, p := range unusedAssets {
historyPath := filepath.Join(historyDir, p)
if p = filepath.Join(util.DataDir, p); gulu.File.IsExist(p) {
if err = gulu.File.Copy(p, historyPath); nil != err {
return
}
hash, _ := util.GetEtag(p)
hashes = append(hashes, hash)
}
}
sql.DeleteAssetsByHashes(hashes)
for _, unusedAsset := range unusedAssets {
if unusedAsset = filepath.Join(util.DataDir, unusedAsset); gulu.File.IsExist(unusedAsset) {
if err := os.RemoveAll(unusedAsset); nil != err {
@ -444,8 +450,13 @@ func RemoveUnusedAsset(p string) (ret string) {
newP := strings.TrimPrefix(p, util.DataDir)
historyPath := filepath.Join(historyDir, newP)
if err = gulu.File.Copy(p, historyPath); nil != err {
return
if gulu.File.IsExist(p) {
if err = gulu.File.Copy(p, historyPath); nil != err {
return
}
hash, _ := util.GetEtag(p)
sql.DeleteAssetsByHashes([]string{hash})
}
if err = os.RemoveAll(p); nil != err {