Commit 3776f311 authored by Austin Clements's avatar Austin Clements

Make os.RemoveAll return no error if path does not exist.

This fixes a problem introduced by CL 32684 into gobuild,
which used to use 'rm -rf' to remove the _obj directory.

R=rsc
APPROVED=rsc
DELTA=8  (4 added, 0 deleted, 4 changed)
OCL=32794
CL=32796
parent d9a0bc9b
...@@ -58,7 +58,8 @@ func MkdirAll(path string, perm int) Error { ...@@ -58,7 +58,8 @@ func MkdirAll(path string, perm int) Error {
// RemoveAll removes path and any children it contains. // RemoveAll removes path and any children it contains.
// It removes everything it can but returns the first error // It removes everything it can but returns the first error
// it encounters. // it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
func RemoveAll(path string) Error { func RemoveAll(path string) Error {
// Simple case: if Remove works, we're done. // Simple case: if Remove works, we're done.
err := Remove(path); err := Remove(path);
...@@ -67,9 +68,12 @@ func RemoveAll(path string) Error { ...@@ -67,9 +68,12 @@ func RemoveAll(path string) Error {
} }
// Otherwise, is this a directory we need to recurse into? // Otherwise, is this a directory we need to recurse into?
dir, err := os.Lstat(path); dir, serr := os.Lstat(path);
if err != nil { if serr != nil {
return err; if serr, ok := serr.(*PathError); ok && serr.Error == ENOENT {
return nil;
}
return serr;
} }
if !dir.IsDirectory() { if !dir.IsDirectory() {
// Not a directory; return the error from Remove. // Not a directory; return the error from Remove.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment