-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileutils.go
52 lines (44 loc) · 1.03 KB
/
fileutils.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package fileutils
import (
"os"
"os/exec"
"path/filepath"
)
// ChmodR is like `chmod -R`
func ChmodR(name string, mode os.FileMode) error {
return filepath.Walk(name, func(path string, info os.FileInfo, err error) error {
if err == nil {
err = os.Chmod(path, mode)
}
return err
})
}
// ChownR is like `chown -R`
func ChownR(path string, uid, gid int) error {
return filepath.Walk(path, func(name string, info os.FileInfo, err error) error {
if err == nil {
err = os.Chown(name, uid, gid)
}
return err
})
}
// MkdirP is `mkdir -p` / os.MkdirAll
func MkdirP(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
}
// Mv is `mv` / os.Rename
func Mv(oldname, newname string) error {
return os.Rename(oldname, newname)
}
// Rm is `rm` / os.Remove
func Rm(name string) error {
return os.Remove(name)
}
// RmRF is `rm -rf` / os.RemoveAll
func RmRF(path string) error {
return os.RemoveAll(path)
}
// Which is `which` / exec.LookPath
func Which(file string) (string, error) {
return exec.LookPath(file)
}