command_fs_mkdir.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package shell
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  5. "github.com/seaweedfs/seaweedfs/weed/util"
  6. "io"
  7. "os"
  8. "time"
  9. )
  10. func init() {
  11. Commands = append(Commands, &commandFsMkdir{})
  12. }
  13. type commandFsMkdir struct {
  14. }
  15. func (c *commandFsMkdir) Name() string {
  16. return "fs.mkdir"
  17. }
  18. func (c *commandFsMkdir) Help() string {
  19. return `create a directory
  20. fs.mkdir path/to/dir
  21. `
  22. }
  23. func (c *commandFsMkdir) HasTag(CommandTag) bool {
  24. return false
  25. }
  26. func (c *commandFsMkdir) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. path, err := commandEnv.parseUrl(findInputDirectory(args))
  28. if err != nil {
  29. return err
  30. }
  31. dir, name := util.FullPath(path).DirAndName()
  32. err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  33. _, createErr := client.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
  34. Directory: dir,
  35. Entry: &filer_pb.Entry{
  36. Name: name,
  37. IsDirectory: true,
  38. Attributes: &filer_pb.FuseAttributes{
  39. Mtime: time.Now().Unix(),
  40. Crtime: time.Now().Unix(),
  41. FileMode: uint32(0777 | os.ModeDir),
  42. },
  43. },
  44. })
  45. return createErr
  46. })
  47. return
  48. }