forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.go
41 lines (34 loc) · 877 Bytes
/
remove.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
package hdfs
import (
"errors"
"os"
hdfs "github.com/colinmarc/hdfs/protocol/hadoop_hdfs"
"github.com/colinmarc/hdfs/rpc"
"github.com/golang/protobuf/proto"
)
// Remove removes the named file or directory.
func (c *SimpleClient) Remove(name string) error {
_, err := c.getFileInfo(name)
if err != nil {
return &os.PathError{"remove", name, err}
}
req := &hdfs.DeleteRequestProto{
Src: proto.String(name),
Recursive: proto.Bool(true),
}
resp := &hdfs.DeleteResponseProto{}
err = c.namenode.Execute("delete", req, resp)
if err != nil {
if nnErr, ok := err.(*rpc.NamenodeError); ok {
err = interpretException(nnErr.Exception, err)
}
return &os.PathError{"remove", name, err}
} else if resp.Result == nil {
return &os.PathError{
"remove",
name,
errors.New("Unexpected empty response to 'delete' rpc call"),
}
}
return nil
}