fix(fs): cannot delete file while user is deleted (fix #1586)

pull/1638/head
Aaron Liu 2 years ago
parent a93ea2cfa0
commit 2a1e82aede

@ -234,7 +234,7 @@ func DeleteFiles(files []*File, uid uint) error {
user.ID = uid user.ID = uid
var size uint64 var size uint64
for _, file := range files { for _, file := range files {
if file.UserID != uid { if uid > 0 && file.UserID != uid {
tx.Rollback() tx.Rollback()
return errors.New("user id not consistent") return errors.New("user id not consistent")
} }
@ -253,9 +253,11 @@ func DeleteFiles(files []*File, uid uint) error {
size += file.Size size += file.Size
} }
if err := user.ChangeStorage(tx, "-", size); err != nil { if uid > 0 {
tx.Rollback() if err := user.ChangeStorage(tx, "-", size); err != nil {
return err tx.Rollback()
return err
}
} }
return tx.Commit().Error return tx.Commit().Error

@ -103,15 +103,22 @@ func (service *FileBatchService) Delete(c *gin.Context) serializer.Response {
// 异步执行删除 // 异步执行删除
go func(files map[uint][]model.File) { go func(files map[uint][]model.File) {
for uid, file := range files { for uid, file := range files {
var (
fs *filesystem.FileSystem
err error
)
user, err := model.GetUserByID(uid) user, err := model.GetUserByID(uid)
if err != nil { if err != nil {
continue fs, err = filesystem.NewAnonymousFileSystem()
} if err != nil {
continue
fs, err := filesystem.NewFileSystem(&user) }
if err != nil { } else {
fs.Recycle() fs, err = filesystem.NewFileSystem(&user)
continue if err != nil {
fs.Recycle()
continue
}
} }
// 汇总文件ID // 汇总文件ID

Loading…
Cancel
Save