Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed false error for implicit dir in rename and remove directory flow #1186

Merged
merged 4 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,9 @@ func (fs *fileSystem) RmDir(
cleanUpAndUnlockChild()

// Delete the backing object.
_, isImplicitDir := fs.implicitDirInodes[child.Name()]
ashmeenkaur marked this conversation as resolved.
Show resolved Hide resolved
parent.Lock()
err = parent.DeleteChildDir(ctx, op.Name)
err = parent.DeleteChildDir(ctx, op.Name, isImplicitDir)
ashmeenkaur marked this conversation as resolved.
Show resolved Hide resolved
parent.Unlock()

if err != nil {
Expand Down Expand Up @@ -1628,8 +1629,9 @@ func (fs *fileSystem) renameDir(
releaseInodes()

// Delete the backing object of the old directory.
_, isImplicitDir := fs.implicitDirInodes[oldDir.Name()]
oldParent.Lock()
err = oldParent.DeleteChildDir(ctx, oldName)
err = oldParent.DeleteChildDir(ctx, oldName, isImplicitDir)
oldParent.Unlock()
if err != nil {
return fmt.Errorf("DeleteChildDir: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/fs/inode/base_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ func (d *baseDirInode) DeleteChildFile(

func (d *baseDirInode) DeleteChildDir(
ctx context.Context,
name string) (err error) {
name string,
isImplicitDir bool) (err error) {
err = fuse.ENOSYS
return
}
11 changes: 8 additions & 3 deletions internal/fs/inode/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ type DirInode interface {
metaGeneration *int64) (err error)

// Delete the backing object for the child directory with the given
// (relative) name.
// (relative) name if it is not an Implicit Directory.
DeleteChildDir(
ctx context.Context,
name string) (err error)
name string,
isImplicitDir bool) (err error)
}

// An inode that represents a directory from a GCS bucket.
Expand Down Expand Up @@ -757,8 +758,12 @@ func (d *dirInode) DeleteChildFile(
// LOCKS_REQUIRED(d)
func (d *dirInode) DeleteChildDir(
ctx context.Context,
name string) (err error) {
name string,
isImplicitDir bool) (err error) {
d.cache.Erase(name)
if isImplicitDir {
ashmeenkaur marked this conversation as resolved.
Show resolved Hide resolved
return
}
childName := NewDirName(d.Name(), name)

// Delete the backing object. Unfortunately we have no way to precondition
Expand Down
11 changes: 9 additions & 2 deletions internal/fs/inode/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ func (t *DirTest) DeleteChildFile_TypeCaching() {
func (t *DirTest) DeleteChildDir_DoesntExist() {
const name = "qux"

err := t.in.DeleteChildDir(t.ctx, name)
err := t.in.DeleteChildDir(t.ctx, name, false)
ExpectEq(nil, err)
}

Expand All @@ -1180,11 +1180,18 @@ func (t *DirTest) DeleteChildDir_Exists() {
AssertEq(nil, err)

// Call the inode.
err = t.in.DeleteChildDir(t.ctx, name)
err = t.in.DeleteChildDir(t.ctx, name, false)
AssertEq(nil, err)

// Check the bucket.
_, err = gcsutil.ReadObject(t.ctx, t.bucket, objName)
var notFoundErr *gcs.NotFoundError
ExpectTrue(errors.As(err, &notFoundErr))
}

func (t *DirTest) DeleteChildDir_ImplicitDirTrue() {
const name = "qux"

err := t.in.DeleteChildDir(t.ctx, name, true)
ExpectEq(nil, err)
}