mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
shell: add fs.mkdir
This commit is contained in:
parent
8dccefbba6
commit
72eec84167
54
weed/shell/command_fs_mkdir.go
Normal file
54
weed/shell/command_fs_mkdir.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Commands = append(Commands, &commandFsMkdir{})
|
||||
}
|
||||
|
||||
type commandFsMkdir struct {
|
||||
}
|
||||
|
||||
func (c *commandFsMkdir) Name() string {
|
||||
return "fs.mkdir"
|
||||
}
|
||||
|
||||
func (c *commandFsMkdir) Help() string {
|
||||
return `create a directory
|
||||
|
||||
fs.mkdir path/to/dir
|
||||
`
|
||||
}
|
||||
|
||||
func (c *commandFsMkdir) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
||||
|
||||
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir, name := util.FullPath(path).DirAndName()
|
||||
|
||||
err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
_, createErr := client.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
|
||||
Directory: dir,
|
||||
Entry: &filer_pb.Entry{
|
||||
Name: name,
|
||||
IsDirectory: true,
|
||||
Attributes: &filer_pb.FuseAttributes{
|
||||
FileMode: uint32(0777 | os.ModeDir),
|
||||
},
|
||||
},
|
||||
})
|
||||
return createErr
|
||||
})
|
||||
|
||||
return
|
||||
}
|
Loading…
Reference in a new issue