forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
32 lines (30 loc) · 742 Bytes
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package vendor
import (
"os"
"path/filepath"
"runtime"
)
// RemoveAll removes path and any children it contains. Unlike os.RemoveAll it
// deletes read only files on Windows.
func RemoveAll(path string) error {
if runtime.GOOS == "windows" {
// Simple case: if Remove works, we're done.
err := os.Remove(path)
if err == nil || os.IsNotExist(err) {
return nil
}
// make sure all files are writable so we can delete them
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
// walk gave us some error, give it back.
return err
}
mode := info.Mode()
if mode|0200 == mode {
return nil
}
return os.Chmod(path, mode|0200)
})
}
return os.RemoveAll(path)
}