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