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

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

Loading…
Cancel
Save