forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chmod.go
49 lines (41 loc) · 757 Bytes
/
chmod.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
package main
import (
"fmt"
"os"
"strconv"
)
func chmod(args []string, recursive bool) {
if len(args) < 2 {
printHelp()
}
mode, err := strconv.ParseUint(args[0], 8, 32)
if err != nil {
fatal("invalid octal mode:", args[0])
}
expanded, client, err := getClientAndExpandedPaths(args[1:])
if err != nil {
fatal(err)
}
visit := func(p string, fi os.FileInfo) {
err := client.Chmod(p, os.FileMode(mode))
if err != nil {
fmt.Fprintln(os.Stderr, err)
status = 1
}
}
for _, p := range expanded {
if recursive {
err = walk(client, p, visit)
if err != nil {
fmt.Fprintln(os.Stderr, err)
status = 1
}
} else {
info, err := client.Stat(p)
if err != nil {
fatal(err)
}
visit(p, info)
}
}
}