Fix: file size is ready dirty when clean upload sessions

After listing to be deleted files, before delete is committed to database, file size might be changed by ongoing upload, causing inconsistent user storage.
This commit is contained in:
HFO4 2022-04-03 20:39:50 +08:00
parent ec776ac837
commit ace398d87b

View file

@ -221,14 +221,17 @@ func DeleteFiles(files []*File, uid uint) error {
for _, file := range files {
if file.UserID != uid {
tx.Rollback()
return errors.New("User id not consistent")
return errors.New("user id not consistent")
}
result := tx.Unscoped().Delete(file)
if result.RowsAffected != 0 {
size += file.Size
result := tx.Unscoped().Where("size = ?", file.Size).Delete(file)
if result.RowsAffected == 0 {
tx.Rollback()
return errors.New("file size is dirty")
}
size += file.Size
if result.Error != nil {
tx.Rollback()
return result.Error