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

Fix gcsfs RemoveAll #340

Merged
merged 4 commits into from Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion gcsfs/file.go
Expand Up @@ -109,7 +109,7 @@ func (o *GcsFile) Seek(newOffset int64, whence int) (int64, error) {
if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) {
return o.fhOffset, nil
}
log.Printf("WARNING: Seek beavhior triggered, highly inefficent. Offset before seek is at %d\n", o.fhOffset)
log.Printf("WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n", o.fhOffset)

//Fore the reader/writers to be reopened (at correct offset)
err := o.Sync()
Expand Down
5 changes: 5 additions & 0 deletions gcsfs/fs.go
Expand Up @@ -325,9 +325,14 @@ func (fs *Fs) RemoveAll(path string) error {
}

pathInfo, err := fs.Stat(path)
if errors.Is(err, ErrFileNotFound) {
// return early if file doesn't exist
return nil
}
if err != nil {
return err
}

if !pathInfo.IsDir() {
return fs.Remove(path)
}
Expand Down
32 changes: 32 additions & 0 deletions gcsfs/gcs_test.go
Expand Up @@ -804,3 +804,35 @@ func TestGcsMkdirAll(t *testing.T) {
}
})
}

func TestGcsRemoveAll(t *testing.T) {
t.Run("non-existent", func(t *testing.T) {
err := gcsAfs.RemoveAll(filepath.Join(bucketName, "a"))
if err != nil {
t.Fatal("error should be nil when removing non-existent file")
}
})
t.Run("success", func(t *testing.T) {
aDir := filepath.Join(bucketName, "a")
bDir := filepath.Join(aDir, "b")

err := gcsAfs.MkdirAll(bDir, 0755)
if err != nil {
t.Fatal(err)
}
_, err = gcsAfs.Stat(bDir)
if err != nil {
t.Fatal(err)
}

err = gcsAfs.RemoveAll(aDir)
if err != nil {
t.Fatalf("failed to remove the folder %s with error: %s", aDir, err)
}

_, err = gcsAfs.Stat(aDir)
if err == nil {
t.Fatalf("folder %s wasn't removed", aDir)
}
})
}