diff --git a/kernel/model/box.go b/kernel/model/box.go index 0b37bfad9..e3f8dc435 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -257,6 +257,16 @@ func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) { if util.IsReservedFilename(name) { continue } + if strings.HasSuffix(name, ".tmp") { + // 移除写入失败时产生的并且早于 30 分钟前的临时文件,近期创建的临时文件可能正在写入中 + removePath := filepath.Join(util.DataDir, box.ID, p, name) + if info.ModTime().Before(time.Now().Add(-30 * time.Minute)) { + if removeErr := os.Remove(removePath); nil != removeErr { + logging.LogWarnf("remove tmp file [%s] failed: %s", removePath, removeErr) + } + } + continue + } totals += 1 fi := &FileInfo{}