forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.go
42 lines (35 loc) · 692 Bytes
/
rm.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
package main
import (
"errors"
"fmt"
"os"
)
func rm(paths []string, recursive bool, force bool) {
expanded, client, err := getClientAndExpandedPaths(paths)
if err != nil {
fatal(err)
}
for _, p := range expanded {
info, err := client.Stat(p)
if err != nil {
if force && os.IsNotExist(err) {
continue
}
if pathErr, ok := err.(*os.PathError); ok {
pathErr.Op = "remove"
}
fmt.Fprintln(os.Stderr, err)
status = 1
continue
}
if !recursive && info.IsDir() {
fmt.Fprintln(os.Stderr, &os.PathError{"remove", p, errors.New("file is a directory")})
status = 1
continue
}
err = client.Remove(p)
if err != nil {
fatal(err)
}
}
}