Implement os.RemoveAll()

TODO: enable test on windows once Readdir is implemented there
This commit is contained in:
Dan Kegel
2022-01-08 16:22:25 -08:00
committed by Ron Evans
parent 4417374b53
commit 47a622a903
7 changed files with 676 additions and 7 deletions
+22 -2
View File
@@ -1,5 +1,5 @@
//go:build !baremetal && !js
// +build !baremetal,!js
//go:build !baremetal
// +build !baremetal
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
@@ -60,3 +60,23 @@ func MkdirAll(path string, perm FileMode) error {
}
return nil
}
// RemoveAll removes path and any children it contains.
// It removes everything it can but returns the first error
// it encounters. If the path does not exist, RemoveAll
// returns nil (no error).
// If there is an error, it will be of type *PathError.
func RemoveAll(path string) error {
return removeAll(path)
}
// 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
}