Fix: unique index check failed due to soft delete

pull/247/head
HFO4 5 years ago
parent fd02425547
commit d28e5632d5

@ -123,7 +123,7 @@ func RemoveFilesWithSoftLinks(files []File) ([]File, error) {
// DeleteFileByIDs 根据给定ID批量删除文件记录
func DeleteFileByIDs(ids []uint) error {
result := DB.Where("id in (?)", ids).Delete(&File{})
result := DB.Where("id in (?)", ids).Unscoped().Delete(&File{})
return result.Error
}

@ -52,7 +52,7 @@ func GetRecursiveChildFolder(dirs []string, uid uint) ([]Folder, error) {
// DeleteFolderByIDs 根据给定ID批量删除目录记录
func DeleteFolderByIDs(ids []uint) error {
result := DB.Where("id in (?)", ids).Delete(&Folder{})
result := DB.Where("id in (?)", ids).Unscoped().Delete(&Folder{})
return result.Error
}
@ -62,14 +62,8 @@ func DeleteFolderByIDs(ids []uint) error {
// MoveFileTo 将此目录下的文件递归移动至dstFolder
func (folder *Folder) MoveFileTo(files []string, dstFolder *Folder) error {
// 生成绝对路径
fullFilePath := make([]string, len(files))
for i := 0; i < len(files); i++ {
fullFilePath[i] = path.Join(folder.PositionAbsolute, files[i])
}
// 更改顶级要移动文件的父目录指向
err := DB.Model(File{}).Where("dir in (?) and user_id = ?", fullFilePath, folder.OwnerID).
err := DB.Model(File{}).Where("dir in (?) and user_id = ?", folder.PositionAbsolute, folder.OwnerID).
Update(map[string]interface{}{
"folder_id": dstFolder.ID,
"dir": dstFolder.PositionAbsolute,

@ -77,6 +77,8 @@ func (fs *FileSystem) Delete(ctx context.Context, dirs, files []string) error {
if err != nil {
return err
}
}
// 去除待删除文件中包含软连接的部分
filesToBeDelete, err := model.RemoveFilesWithSoftLinks(fs.FileTarget)
if err != nil {
@ -98,10 +100,9 @@ func (fs *FileSystem) Delete(ctx context.Context, dirs, files []string) error {
deletedStorage[fs.FileTarget[i].ID] = fs.FileTarget[i].Size
allFileIDs = append(allFileIDs, fs.FileTarget[i].ID)
}
}
// 删除文件记录
err := model.DeleteFileByIDs(allFileIDs)
err = model.DeleteFileByIDs(allFileIDs)
if err != nil {
return ErrDBDeleteObjects.WithError(err)
}

@ -31,6 +31,7 @@ type Policy struct {
MaxSize string `json:"maxSize"`
AllowedType []string `json:"allowedType"`
UploadURL string `json:"upUrl"`
AllowGetSource bool `json:"allowSource"`
}
type Group struct {
@ -55,6 +56,7 @@ func BuildUser(user model.User) User {
MaxSize: fmt.Sprintf("%.2fmb", float64(user.Policy.MaxSize)/1024*1024),
AllowedType: user.Policy.OptionsSerialized.FileType,
UploadURL: user.Policy.Server,
AllowGetSource: user.Policy.IsOriginLinkEnable,
},
Group: Group{
AllowShare: user.Group.ShareEnabled,

Loading…
Cancel
Save