Skip to content

Commit f7305ea

Browse files
committed
remove checkDirNotEmpty validation
1 parent 9651ba5 commit f7305ea

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

internal/fs/fs.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,18 +2655,6 @@ func (fs *fileSystem) ensureNoLocalFilesInDirectory(dir inode.BucketOwnedDirInod
26552655
return nil
26562656
}
26572657

2658-
func (fs *fileSystem) checkDirNotEmpty(dir inode.BucketOwnedDirInode, name string) error {
2659-
unexpected, err := dir.ReadDescendants(context.Background(), 1)
2660-
if err != nil {
2661-
return fmt.Errorf("read descendants of the new directory %q: %w", name, err)
2662-
}
2663-
2664-
if len(unexpected) > 0 {
2665-
return fuse.ENOTEMPTY
2666-
}
2667-
return nil
2668-
}
2669-
26702658
// Rename an old folder to a new folder in a hierarchical bucket. If the new folder already
26712659
// exists and is non-empty, return ENOTEMPTY. If old folder have open files then return
26722660
// ENOTSUP.
@@ -2697,14 +2685,10 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode
26972685
// If the call for getBucketDirInode fails it means directory does not exist.
26982686
newDirInode, err := fs.getBucketDirInode(ctx, newParent, newName)
26992687
if err == nil {
2700-
// If the directory exists, then check if it is empty or not.
2701-
if err = fs.checkDirNotEmpty(newDirInode, newName); err != nil {
2702-
return err
2703-
}
2704-
2705-
// This refers to an empty destination directory.
2706-
// The RenameFolder API does not allow renaming to an existing empty directory.
2707-
// To make this work, we delete the empty directory first from gcsfuse and then perform rename.
2688+
// The RenameFolder API does not allow renaming to an existing directory.
2689+
// To make this work, we attempt to delete the destination directory first.
2690+
// If it is non-empty, this deletion will fail (and we ignore the error here),
2691+
// and the subsequent RenameFolder call will fail, returning ENOTEMPTY.
27082692
newParent.Lock()
27092693
_ = newParent.DeleteChildDir(ctx, newName, false, newDirInode)
27102694
newParent.Unlock()
@@ -2723,12 +2707,28 @@ func (fs *fileSystem) renameHierarchicalDir(ctx context.Context, oldParent inode
27232707
// Rename old directory to the new directory, keeping both parent directories locked.
27242708
_, err = oldParent.RenameFolder(ctx, oldDirName.GcsObjectName(), newDirName.GcsObjectName(), oldDirInode)
27252709
if err != nil {
2710+
var precondErr *gcs.PreconditionError
2711+
if errors.As(err, &precondErr) {
2712+
return fuse.ENOTEMPTY
2713+
}
27262714
return fmt.Errorf("failed to rename folder: %w", err)
27272715
}
27282716

27292717
return
27302718
}
27312719

2720+
func (fs *fileSystem) checkDirNotEmpty(dir inode.BucketOwnedDirInode, name string) error {
2721+
unexpected, err := dir.ReadDescendants(context.Background(), 1)
2722+
if err != nil {
2723+
return fmt.Errorf("read descendants of the new directory %q: %w", name, err)
2724+
}
2725+
2726+
if len(unexpected) > 0 {
2727+
return fuse.ENOTEMPTY
2728+
}
2729+
return nil
2730+
}
2731+
27322732
// Rename an old directory to a new directory in a non-hierarchical bucket. If the new directory already
27332733
// exists and is non-empty, return ENOTEMPTY.
27342734
//

0 commit comments

Comments
 (0)