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:
parent
ec776ac837
commit
ace398d87b
1 changed files with 7 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue