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.

71 lines
1.6 KiB

3 months ago
5 years ago
5 years ago
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  7. "io"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  9. )
  10. func init() {
  11. Commands = append(Commands, &commandS3BucketDelete{})
  12. }
  13. type commandS3BucketDelete struct {
  14. }
  15. func (c *commandS3BucketDelete) Name() string {
  16. return "s3.bucket.delete"
  17. }
  18. func (c *commandS3BucketDelete) Help() string {
  19. return `delete a bucket by a given name
  20. s3.bucket.delete -name <bucket_name>
  21. `
  22. }
  23. func (c *commandS3BucketDelete) HasTag(CommandTag) bool {
  24. return false
  25. }
  26. func (c *commandS3BucketDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  28. bucketName := bucketCommand.String("name", "", "bucket name")
  29. if err = bucketCommand.Parse(args); err != nil {
  30. return nil
  31. }
  32. if *bucketName == "" {
  33. return fmt.Errorf("empty bucket name")
  34. }
  35. _, parseErr := commandEnv.parseUrl(findInputDirectory(bucketCommand.Args()))
  36. if parseErr != nil {
  37. return parseErr
  38. }
  39. var filerBucketsPath string
  40. filerBucketsPath, err = readFilerBucketsPath(commandEnv)
  41. if err != nil {
  42. return fmt.Errorf("read buckets: %v", err)
  43. }
  44. // delete the collection directly first
  45. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  46. _, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
  47. Name: getCollectionName(commandEnv, *bucketName),
  48. })
  49. return err
  50. })
  51. if err != nil {
  52. return
  53. }
  54. return filer_pb.Remove(commandEnv, filerBucketsPath, *bucketName, false, true, true, false, nil)
  55. }