seaweedfs/weed/shell/command_s3_bucket_delete.go

68 lines
1.5 KiB
Go
Raw Normal View History

2020-02-25 07:30:01 +00:00
package shell
import (
"context"
2020-02-25 07:30:01 +00:00
"flag"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
2020-02-25 07:30:01 +00:00
"io"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
2020-02-25 07:30:01 +00:00
)
func init() {
Commands = append(Commands, &commandS3BucketDelete{})
2020-02-25 07:30:01 +00:00
}
type commandS3BucketDelete struct {
2020-02-25 07:30:01 +00:00
}
func (c *commandS3BucketDelete) Name() string {
return "s3.bucket.delete"
2020-02-25 07:30:01 +00:00
}
func (c *commandS3BucketDelete) Help() string {
2020-02-25 07:30:01 +00:00
return `delete a bucket by a given name
s3.bucket.delete -name <bucket_name>
2020-02-25 07:30:01 +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
// delete the collection directly first
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
_, err = client.CollectionDelete(context.Background(), &master_pb.CollectionDeleteRequest{
Name: getCollectionName(commandEnv, *bucketName),
})
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
}