Skip to content

Commit

Permalink
🎨 Improve removing unused assets
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 30, 2024
1 parent 258d55b commit ba9f41a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kernel/model/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,19 @@ func RemoveUnusedAssets() (ret []string) {
sql.BatchRemoveAssetsQueue(hashes)

for _, unusedAsset := range unusedAssets {
if unusedAsset = filepath.Join(util.DataDir, unusedAsset); filelock.IsExist(unusedAsset) {
info, statErr := os.Stat(unusedAsset)
absPath := filepath.Join(util.DataDir, unusedAsset)
if filelock.IsExist(absPath) {
info, statErr := os.Stat(absPath)
if statErr == nil {
size += info.Size()
}

if err := filelock.Remove(unusedAsset); err != nil {
logging.LogErrorf("remove unused asset [%s] failed: %s", unusedAsset, err)
if err := filelock.Remove(absPath); err != nil {
logging.LogErrorf("remove unused asset [%s] failed: %s", absPath, err)
}
util.RemoveAssetText(unusedAsset)
}
ret = append(ret, unusedAsset)
ret = append(ret, absPath)
}
if 0 < len(ret) {
IncSync()
Expand Down Expand Up @@ -569,6 +571,9 @@ func RemoveUnusedAsset(p string) (ret string) {
logging.LogErrorf("remove unused asset [%s] failed: %s", absPath, err)
}
ret = absPath

util.RemoveAssetText(p)

IncSync()

indexHistoryDir(filepath.Base(historyDir), util.NewLute())
Expand Down

0 comments on commit ba9f41a

Please sign in to comment.