mirror of https://github.com/spf13/afero.git
Merge pull request #340 from typerat/fix-gcsfs-removeall-notfound
Fix gcsfs RemoveAll
This commit is contained in:
commit
931302a103
|
@ -109,7 +109,7 @@ func (o *GcsFile) Seek(newOffset int64, whence int) (int64, error) {
|
||||||
if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) {
|
if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) {
|
||||||
return o.fhOffset, nil
|
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)
|
//Fore the reader/writers to be reopened (at correct offset)
|
||||||
err := o.Sync()
|
err := o.Sync()
|
||||||
|
|
|
@ -325,9 +325,14 @@ func (fs *Fs) RemoveAll(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pathInfo, err := fs.Stat(path)
|
pathInfo, err := fs.Stat(path)
|
||||||
|
if errors.Is(err, ErrFileNotFound) {
|
||||||
|
// return early if file doesn't exist
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pathInfo.IsDir() {
|
if !pathInfo.IsDir() {
|
||||||
return fs.Remove(path)
|
return fs.Remove(path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue