]> Cypherpunks repositories - gostls13.git/commitdiff
os: prevent RemoveAll to remove "." on Plan 9
authorDavid du Colombier <0intro@gmail.com>
Wed, 21 Nov 2018 23:06:42 +0000 (00:06 +0100)
committerDavid du Colombier <0intro@gmail.com>
Wed, 21 Nov 2018 23:29:43 +0000 (23:29 +0000)
CL 150497 enabled TestRemoveAllDot on "noat" systems.

However, this test is failing on Plan 9 because the rmdir
system call allows to remove "." on Plan 9.

This change prevents the "noat" implementation of RemoveAll to
remove ".", so it remains consistent with the "at" implementation.

Fixes #28903.

Change-Id: Ifc8fe36bdd8053a4e416f0590663c844c97ce72a
Reviewed-on: https://go-review.googlesource.com/c/150621
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/path.go
src/os/removeall_at.go
src/os/removeall_noat.go

index e31f64c750ef2d35b31a7901401951fa6677744c..30cc6c8b9841e2db83cf674977b87f99d5dda89a 100644 (file)
@@ -57,3 +57,14 @@ func MkdirAll(path string, perm FileMode) error {
        }
        return nil
 }
+
+// endsWithDot reports whether the final component of path is ".".
+func endsWithDot(path string) bool {
+       if path == "." {
+               return true
+       }
+       if len(path) >= 2 && path[len(path)-1] == '.' && IsPathSeparator(path[len(path)-2]) {
+               return true
+       }
+       return false
+}
index 777690ec661056557fe9e129a568a33a28441dee..c42319a831282bcdb6b0461b8eb42a9a0fae0a03 100644 (file)
@@ -130,14 +130,3 @@ func openFdAt(fd int, path string) (*File, error) {
 
        return NewFile(uintptr(fd), path), nil
 }
-
-// endsWithDot returns whether the final component of path is ".".
-func endsWithDot(path string) bool {
-       if path == "." {
-               return true
-       }
-       if len(path) >= 2 && path[len(path)-1] == '.' && IsPathSeparator(path[len(path)-2]) {
-               return true
-       }
-       return false
-}
index d382b42af33f93a47a952386239f9bb4d87ca7f8..80527e227c9964cbb631db7cd42445bbf9c416b9 100644 (file)
@@ -22,6 +22,13 @@ func RemoveAll(path string) error {
                return nil
        }
 
+       // The rmdir system call permits removing "." on Plan 9,
+       // so we don't permit it to remain consistent with the
+       // "at" implementation of RemoveAll.
+       if endsWithDot(path) {
+               return &PathError{"RemoveAll", path, syscall.EINVAL}
+       }
+
        // Simple case: if Remove works, we're done.
        err := Remove(path)
        if err == nil || IsNotExist(err) {