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.

57 lines
1.1 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. "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) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  24. path, err := commandEnv.parseUrl(findInputDirectory(args))
  25. if err != nil {
  26. return err
  27. }
  28. dir, name := util.FullPath(path).DirAndName()
  29. err = commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  30. _, createErr := client.CreateEntry(context.Background(), &filer_pb.CreateEntryRequest{
  31. Directory: dir,
  32. Entry: &filer_pb.Entry{
  33. Name: name,
  34. IsDirectory: true,
  35. Attributes: &filer_pb.FuseAttributes{
  36. Mtime: time.Now().Unix(),
  37. Crtime: time.Now().Unix(),
  38. FileMode: uint32(0777 | os.ModeDir),
  39. },
  40. },
  41. })
  42. return createErr
  43. })
  44. return
  45. }