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