mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
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:
@@ -221,14 +221,17 @@ func DeleteFiles(files []*File, uid uint) error {
|
|||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.UserID != uid {
|
if file.UserID != uid {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return errors.New("User id not consistent")
|
return errors.New("user id not consistent")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := tx.Unscoped().Delete(file)
|
result := tx.Unscoped().Where("size = ?", file.Size).Delete(file)
|
||||||
if result.RowsAffected != 0 {
|
if result.RowsAffected == 0 {
|
||||||
size += file.Size
|
tx.Rollback()
|
||||||
|
return errors.New("file size is dirty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size += file.Size
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return result.Error
|
return result.Error
|
||||||
|
|||||||
Reference in New Issue
Block a user