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.

54 lines
1.0 KiB

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