2021-07-25 17:27:30 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2021-07-25 17:27:30 +08:00
|
|
|
"io"
|
|
|
|
"os"
|
2021-08-06 11:13:37 +08:00
|
|
|
"time"
|
2021-07-25 17:27:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2021-12-26 16:15:03 +08:00
|
|
|
err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2021-07-25 17:27:30 +08:00
|
|
|
|
|
|
|
_, createErr := client.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
|
|
|
|
Directory: dir,
|
|
|
|
Entry: &filer_pb.Entry{
|
|
|
|
Name: name,
|
|
|
|
IsDirectory: true,
|
|
|
|
Attributes: &filer_pb.FuseAttributes{
|
2021-08-06 11:13:37 +08:00
|
|
|
Mtime: time.Now().Unix(),
|
|
|
|
Crtime: time.Now().Unix(),
|
2021-07-25 17:27:30 +08:00
|
|
|
FileMode: uint32(0777 | os.ModeDir),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return createErr
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|