1 Star 0 Fork 0

zx/hdfs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mkdir.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
Ashish Gandhi 提交于 2015-11-24 08:19 +08:00 . all: run goimports -w -l .
package hdfs
import (
"os"
"path"
hdfs "github.com/colinmarc/hdfs/protocol/hadoop_hdfs"
"github.com/colinmarc/hdfs/rpc"
"github.com/golang/protobuf/proto"
)
// Mkdir creates a new directory with the specified name and permission bits.
func (c *Client) Mkdir(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, false)
}
// MkdirAll creates a directory for dirname, along with any necessary parents,
// and returns nil, or else returns an error. The permission bits perm are used
// for all directories that MkdirAll creates. If dirname is already a directory,
// MkdirAll does nothing and returns nil.
func (c *Client) MkdirAll(dirname string, perm os.FileMode) error {
return c.mkdir(dirname, perm, true)
}
func (c *Client) mkdir(dirname string, perm os.FileMode, createParent bool) error {
dirname = path.Clean(dirname)
info, err := c.getFileInfo(dirname)
if err == nil {
if createParent && info.IsDir() {
return nil
}
return &os.PathError{"mkdir", dirname, os.ErrExist}
} else if !os.IsNotExist(err) {
return &os.PathError{"mkdir", dirname, err}
}
req := &hdfs.MkdirsRequestProto{
Src: proto.String(dirname),
Masked: &hdfs.FsPermissionProto{Perm: proto.Uint32(uint32(perm))},
CreateParent: proto.Bool(createParent),
}
resp := &hdfs.MkdirsResponseProto{}
err = c.namenode.Execute("mkdirs", req, resp)
if err != nil {
if nnErr, ok := err.(*rpc.NamenodeError); ok {
err = interpretException(nnErr.Exception, err)
}
return &os.PathError{"mkdir", dirname, err}
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/z_matrix/hdfs.git
git@gitee.com:z_matrix/hdfs.git
z_matrix
hdfs
hdfs
v1.1.3

搜索帮助