Fix: trigger err when move folder into itself (#1128)
This commit is contained in:
parent
c31c77a089
commit
c84d0114ae
2 changed files with 15 additions and 1 deletions
|
@ -263,6 +263,13 @@ func (folder *Folder) CopyFolderTo(folderID uint, dstFolder *Folder) (size uint6
|
|||
// MoveFolderTo 将folder目录下的dirs子目录复制或移动到dstFolder,
|
||||
// 返回此过程中增加的容量
|
||||
func (folder *Folder) MoveFolderTo(dirs []uint, dstFolder *Folder) error {
|
||||
|
||||
// 如果目标位置为待移动的目录,会导致 parent 为自己
|
||||
// 造成死循环且无法被除搜索以外的组件展示
|
||||
if folder.OwnerID == dstFolder.OwnerID && util.ContainsUint(dirs, dstFolder.ID) {
|
||||
return errors.New("cannot move a folder into itself")
|
||||
}
|
||||
|
||||
// 更改顶级要移动目录的父目录指向
|
||||
err := DB.Model(Folder{}).Where(
|
||||
"id in (?) and owner_id = ? and parent_id = ?",
|
||||
|
|
|
@ -493,7 +493,8 @@ func TestFolder_MoveOrCopyFolderTo_Move(t *testing.T) {
|
|||
}
|
||||
// 目标目录
|
||||
dstFolder := Folder{
|
||||
Model: gorm.Model{ID: 10},
|
||||
Model: gorm.Model{ID: 10},
|
||||
OwnerID: 1,
|
||||
}
|
||||
|
||||
// 成功
|
||||
|
@ -507,6 +508,12 @@ func TestFolder_MoveOrCopyFolderTo_Move(t *testing.T) {
|
|||
asserts.NoError(mock.ExpectationsWereMet())
|
||||
asserts.NoError(err)
|
||||
}
|
||||
|
||||
// 移动自己到自己内部,失败
|
||||
{
|
||||
err := parFolder.MoveFolderTo([]uint{10, 2}, &dstFolder)
|
||||
asserts.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFolder_FileInfoInterface(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue