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>
)
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
}
// 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) {
}
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")