Skip to content

Commit

Permalink
add delete command for empty folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tulsishah committed Oct 9, 2024
1 parent f2d240d commit 2b6439a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2090,20 +2090,25 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode
return err
}

oldDirName := inode.NewDirName(oldParent.Name(), oldName)
newDirName := inode.NewDirName(newParent.Name(), newName)

// If the call for getBucketDirInode fails it means directory does not exist.
newDirInode, err := fs.getBucketDirInode(ctx, newParent, newName)
if err == nil {
// If the directory exists, then check if it is empty or not.
if err = fs.checkDirNotEmpty(newDirInode, newName); err != nil {
return err
}
// It refers empty dest directory
// Since RenameFolder APIis not allowing to rename existing empty directory. We are deleting it first and then doing rename.
newParent.Lock()
err = newParent.DeleteChildDir(ctx, newDirName.GcsObjectName(), false, newDirInode)
newParent.Unlock()
pendingInodes = append(pendingInodes, newDirInode)
}

// Note:The renameDirLimit is not utilized in the folder rename operation because there is no user-defined limit on new renames.

oldDirName := inode.NewDirName(oldParent.Name(), oldName)
newDirName := inode.NewDirName(newParent.Name(), newName)
oldParent.Lock()
defer oldParent.Unlock()

Expand Down

0 comments on commit 2b6439a

Please sign in to comment.