Skip to content

Commit

Permalink
Do not allow renaming into a non-empty directory
Browse files Browse the repository at this point in the history
This allows pjdfstest rename/20.t to pass.  References
#590.
  • Loading branch information
gaul authored and lezh committed Feb 6, 2022
1 parent 509d6c0 commit cbbe567
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1501,14 +1501,20 @@ func (fs *fileSystem) renameDir(
}
pendingInodes = append(pendingInodes, oldDir)

// Fetch all the descendants of the directory recuirsively
// Fetch all the descendants of the old directory recursively
descendants, err := oldDir.ReadDescendants(ctx, int(fs.renameDirLimit+1))
if len(descendants) > int(fs.renameDirLimit) {
return fmt.Errorf("too many objects to be renamed: %w", syscall.EMFILE)
}

// Create the backing object of the new directory.
newParent.Lock()
// Fetch a single descendant of the new parent
if newParentDescendents, err := newParent.ReadDescendants(ctx, 1); err == nil && len(newParentDescendents) > 0 {
newParent.Unlock()
return fuse.ENOTEMPTY
}

// Create the backing object of the new directory.
_, err = newParent.CreateChildDir(ctx, newName)
newParent.Unlock()
if err != nil {
Expand Down

0 comments on commit cbbe567

Please sign in to comment.