Skip to content

Commit

Permalink
enhance abort-upload to abort all uploads for given key
Browse files Browse the repository at this point in the history
Signed-off-by: Dweb Fan <[email protected]>
  • Loading branch information
dwebfan committed May 19, 2024
1 parent 6ecaa65 commit 34dcb24
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/lomob/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ func main() {
{
Name: "abort-upload",
Action: abortUpload,
Usage: "Abort in progress upload",
ArgsUsage: "[upload key] [upload ID]",
Usage: "Abort in progress upload. If upload ID is not provided, it will delete all upload for given key",
ArgsUsage: "[upload key] [[upload ID]]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "awsAccessKeyID",
Expand Down
45 changes: 38 additions & 7 deletions cmd/lomob/upload-iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@ func listUploadingItems(ctx *cli.Context) error {
}

func abortUpload(ctx *cli.Context) error {
if len(ctx.Args()) == 0 {
return errors.New("please provide upload key at least")
}
accessKeyID := ctx.String("awsAccessKeyID")
secretAccessKey := ctx.String("awsSecretAccessKey")
region := ctx.String("awsBucketRegion")
Expand All @@ -571,15 +574,43 @@ func abortUpload(ctx *cli.Context) error {
return err
}

err = cli.AbortMultipartUpload(&clients.UploadRequest{
Key: ctx.Args()[0],
ID: ctx.Args()[1],
Bucket: bucket,
})
uploadKey := ctx.Args()[0]
if len(ctx.Args()) > 1 {
err = cli.AbortMultipartUpload(&clients.UploadRequest{
Key: uploadKey,
ID: ctx.Args()[1],
Bucket: bucket,
})
if err != nil {
return err
}
fmt.Println("abort upload success")
return nil
}

requests, err := cli.ListMultipartUploads(bucket)
if err != nil {
return err
return errors.Wrap(err, "while listing all multi part uploads")
}
if len(requests) == 0 {
fmt.Println("no in progress multipart upload to abort")
return nil
}
for _, r := range requests {
if r.Key != uploadKey {
continue
}
err = cli.AbortMultipartUpload(&clients.UploadRequest{
Key: uploadKey,
ID: r.ID,
Bucket: bucket,
})
if err != nil {
fmt.Printf("abort upload ID %s: %s\n", r.ID, err)
} else {
fmt.Printf("abort upload ID %s success!\n", r.ID)
}
}
fmt.Println("abort upload success")
return nil
}

Expand Down

0 comments on commit 34dcb24

Please sign in to comment.