From e08384e901fa07f4a5a7ea3563b98fb903318db3 Mon Sep 17 00:00:00 2001 From: Christoph Armster Date: Tue, 22 Feb 2022 09:06:46 +0100 Subject: [PATCH 1/4] return no error if file doesn't exist --- gcsfs/fs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcsfs/fs.go b/gcsfs/fs.go index dc099b1..51db995 100644 --- a/gcsfs/fs.go +++ b/gcsfs/fs.go @@ -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) } From 25e8a0a4c80034b28693ab75fcf35ad53b293c7c Mon Sep 17 00:00:00 2001 From: Christoph Armster Date: Tue, 22 Feb 2022 09:09:00 +0100 Subject: [PATCH 2/4] fix typo --- gcsfs/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcsfs/file.go b/gcsfs/file.go index a3d491e..f916bd2 100644 --- a/gcsfs/file.go +++ b/gcsfs/file.go @@ -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() From d6369bbece937d8ef33ab1fd75bdbf0bcf93656f Mon Sep 17 00:00:00 2001 From: Christoph Armster Date: Tue, 22 Feb 2022 09:31:52 +0100 Subject: [PATCH 3/4] add test for RemoveAll --- gcsfs/gcs_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gcsfs/gcs_test.go b/gcsfs/gcs_test.go index 671787c..4313076 100644 --- a/gcsfs/gcs_test.go +++ b/gcsfs/gcs_test.go @@ -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("failed 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) + } + }) +} From b25fb10d4f24828fdc0202b415a2114afeddd389 Mon Sep 17 00:00:00 2001 From: Christoph Armster Date: Thu, 10 Mar 2022 08:24:52 +0100 Subject: [PATCH 4/4] clarify error message --- gcsfs/gcs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcsfs/gcs_test.go b/gcsfs/gcs_test.go index 4313076..0809c2b 100644 --- a/gcsfs/gcs_test.go +++ b/gcsfs/gcs_test.go @@ -809,7 +809,7 @@ 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("failed when removing non-existent file") + t.Fatal("error should be nil when removing non-existent file") } }) t.Run("success", func(t *testing.T) {