From: Austin Clements Date: Wed, 5 Aug 2009 21:18:54 +0000 (-0700) Subject: Make os.RemoveAll return no error if path does not exist. X-Git-Tag: weekly.2009-11-06~963 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3776f31144035c7d3e187888b8f5debbc62d3e5f;p=gostls13.git 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 --- diff --git a/src/pkg/os/path.go b/src/pkg/os/path.go index d8efe51832..586760e383 100644 --- a/src/pkg/os/path.go +++ b/src/pkg/os/path.go @@ -58,7 +58,8 @@ func MkdirAll(path string, perm int) Error { // RemoveAll removes path and any children it contains. // 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 { // Simple case: if Remove works, we're done. err := Remove(path); @@ -67,9 +68,12 @@ func RemoveAll(path string) Error { } // Otherwise, is this a directory we need to recurse into? - dir, err := os.Lstat(path); - if err != nil { - return err; + dir, serr := os.Lstat(path); + if serr != nil { + if serr, ok := serr.(*PathError); ok && serr.Error == ENOENT { + return nil; + } + return serr; } if !dir.IsDirectory() { // Not a directory; return the error from Remove.