]> Cypherpunks repositories - gostls13.git/commitdiff
os: make RemoveAll("") fail silently on unix
authorTobias Klauser <tklauser@distanz.ch>
Sat, 17 Nov 2018 13:09:24 +0000 (14:09 +0100)
committerTobias Klauser <tobias.klauser@gmail.com>
Sun, 18 Nov 2018 16:13:13 +0000 (16:13 +0000)
CL 146020 changed the behavior of RemoveAll("") on unix systems using
the *at functions to return syscall.EINVAL instead of nil. Adjust the
*at implementation to retain this behavior as is the case on the *noat
systems.

Additionally, also make sure RemoveAll("") on systems not using the "at
functions (e.g. nacl and js/wasm) follow the same behavior (which wasn't
the case previously).

Fixes #28830

Change-Id: I8383c1423fefe871d18ff49134a1d23077ec6867
Reviewed-on: https://go-review.googlesource.com/c/150158
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: roger peppe <rogpeppe@gmail.com>
src/os/removeall_at.go
src/os/removeall_noat.go
src/os/removeall_test.go

index eb220bd103f0c1fe4ba93eabac9d5f7bcfdb83de..5aa1b46117158c6575c8514a2437301b99876eea 100644 (file)
@@ -13,8 +13,14 @@ import (
 )
 
 func RemoveAll(path string) error {
+       if path == "" {
+               // fail silently to retain compatibility with previous behavior
+               // of RemoveAll. See issue 28830.
+               return nil
+       }
+
        // Not allowed in unix
-       if path == "" || endsWithDot(path) {
+       if endsWithDot(path) {
                return syscall.EINVAL
        }
 
index d1dd43ff6ac44d41cbf7776d3102d8c5520baad3..d382b42af33f93a47a952386239f9bb4d87ca7f8 100644 (file)
@@ -16,6 +16,12 @@ import (
 // it encounters. If the path does not exist, RemoveAll
 // returns nil (no error).
 func RemoveAll(path string) error {
+       if path == "" {
+               // fail silently to retain compatibility with previous behavior
+               // of RemoveAll. See issue 28830.
+               return nil
+       }
+
        // Simple case: if Remove works, we're done.
        err := Remove(path)
        if err == nil || IsNotExist(err) {
index 5eec8cd1547310ec2549e65c5f7870a39510bd6e..fd3b8d22f980de8bce5092af42ad9e793f1f2166 100644 (file)
@@ -21,6 +21,10 @@ func TestRemoveAll(t *testing.T) {
        }
        defer RemoveAll(tmpDir)
 
+       if err := RemoveAll(""); err != nil {
+               t.Errorf("RemoveAll(\"\"): %v; want nil", err)
+       }
+
        file := filepath.Join(tmpDir, "file")
        path := filepath.Join(tmpDir, "_TestRemoveAll_")
        fpath := filepath.Join(path, "file")