2020-02-25 07:30:01 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2021-07-23 18:25:43 +00:00
|
|
|
"context"
|
2020-02-25 07:30:01 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
2020-02-25 07:30:01 +00:00
|
|
|
"io"
|
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
2020-02-25 07:30:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-12-23 01:40:55 +00:00
|
|
|
Commands = append(Commands, &commandS3BucketDelete{})
|
2020-02-25 07:30:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 01:40:55 +00:00
|
|
|
type commandS3BucketDelete struct {
|
2020-02-25 07:30:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 01:40:55 +00:00
|
|
|
func (c *commandS3BucketDelete) Name() string {
|
|
|
|
return "s3.bucket.delete"
|
2020-02-25 07:30:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 01:40:55 +00:00
|
|
|
func (c *commandS3BucketDelete) Help() string {
|
2020-02-25 07:30:01 +00:00
|
|
|
return `delete a bucket by a given name
|
|
|
|
|
2020-12-23 01:40:55 +00:00
|
|
|
s3.bucket.delete -name <bucket_name>
|
2020-02-25 07:30:01 +00:00
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2020-12-23 01:40:55 +00:00
|
|
|
func (c *commandS3BucketDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2020-02-25 07:30:01 +00:00
|
|
|
|
|
|
|
bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
|
|
bucketName := bucketCommand.String("name", "", "bucket name")
|
|
|
|
if err = bucketCommand.Parse(args); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if *bucketName == "" {
|
|
|
|
return fmt.Errorf("empty bucket name")
|
|
|
|
}
|
|
|
|
|
2020-03-24 04:26:15 +00:00
|
|
|
_, parseErr := commandEnv.parseUrl(findInputDirectory(bucketCommand.Args()))
|
2020-02-25 07:30:01 +00:00
|
|
|
if parseErr != nil {
|
|
|
|
return parseErr
|
|
|
|
}
|
|
|
|
|
2020-03-23 08:14:21 +00:00
|
|
|
var filerBucketsPath string
|
2020-03-24 04:26:15 +00:00
|
|
|
filerBucketsPath, err = readFilerBucketsPath(commandEnv)
|
2020-03-23 08:14:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("read buckets: %v", err)
|
|
|
|
}
|
2020-02-25 07:30:01 +00:00
|
|
|
|
2021-07-23 18:25:43 +00:00
|
|
|
// delete the collection directly first
|
2021-12-26 08:15:03 +00:00
|
|
|
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
|
2021-07-23 18:25:43 +00:00
|
|
|
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
|
2023-05-16 16:39:43 +00:00
|
|
|
Name: getCollectionName(commandEnv, *bucketName),
|
2021-07-23 18:25:43 +00:00
|
|
|
})
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-09 18:21:23 +00:00
|
|
|
return filer_pb.Remove(commandEnv, filerBucketsPath, *bucketName, false, true, true, false, nil)
|
2020-02-25 07:30:01 +00:00
|
|
|
|
|
|
|
}
|