forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.go
36 lines (30 loc) · 865 Bytes
/
rename.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
package hdfs
import (
"code.google.com/p/goprotobuf/proto"
hdfs "github.com/colinmarc/hdfs/protocol/hadoop_hdfs"
"github.com/colinmarc/hdfs/rpc"
"os"
)
// Rename renames (moves) a file.
func (c *Client) Rename(oldpath, newpath string) error {
_, err := c.getFileInfo(newpath)
if err == nil {
return &os.PathError{"rename", newpath, os.ErrExist}
} else if !os.IsNotExist(err) {
return &os.PathError{"rename", newpath, err}
}
req := &hdfs.Rename2RequestProto{
Src: proto.String(oldpath),
Dst: proto.String(newpath),
OverwriteDest: proto.Bool(true),
}
resp := &hdfs.Rename2ResponseProto{}
err = c.namenode.Execute("rename2", req, resp)
if err != nil {
if nnErr, ok := err.(*rpc.NamenodeError); ok {
err = interpretException(nnErr.Exception, err)
}
return &os.PathError{"rename", oldpath, err}
}
return nil
}