You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

3 months ago
  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. }