Skip to content

Commit

Permalink
RemoveIncompleteUpload to remove all incomplete uploads (#994)
Browse files Browse the repository at this point in the history
Currently RemoveIncompleteUpload removes only the latest
incomplete upload for an object. Fix will remove all the
incomplete uploads available for an object.
  • Loading branch information
kannappanr authored Jun 19, 2018
1 parent 651b81a commit f45f891
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 6 additions & 9 deletions api-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,30 +633,27 @@ func (c Client) listObjectParts(bucketName, objectName, uploadID string) (partsI
return partsInfo, nil
}

// findUploadID lists all incomplete uploads and finds the uploadID of the matching object name.
func (c Client) findUploadID(bucketName, objectName string) (uploadID string, err error) {
// findUploadIDs lists all incomplete uploads and find the uploadIDs of the matching object name.
func (c Client) findUploadIDs(bucketName, objectName string) ([]string, error) {
var uploadIDs []string
// Make list incomplete uploads recursive.
isRecursive := true
// Turn off size aggregation of individual parts, in this request.
isAggregateSize := false
// latestUpload to track the latest multipart info for objectName.
var latestUpload ObjectMultipartInfo
// Create done channel to cleanup the routine.
doneCh := make(chan struct{})
defer close(doneCh)
// List all incomplete uploads.
for mpUpload := range c.listIncompleteUploads(bucketName, objectName, isRecursive, isAggregateSize, doneCh) {
if mpUpload.Err != nil {
return "", mpUpload.Err
return nil, mpUpload.Err
}
if objectName == mpUpload.Key {
if mpUpload.Initiated.Sub(latestUpload.Initiated) > 0 {
latestUpload = mpUpload
}
uploadIDs = append(uploadIDs, mpUpload.UploadID)
}
}
// Return the latest upload id.
return latestUpload.UploadID, nil
return uploadIDs, nil
}

// getTotalMultipartSize - calculate total uploaded size for the a given multipart object.
Expand Down
10 changes: 6 additions & 4 deletions api-remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,20 @@ func (c Client) RemoveIncompleteUpload(bucketName, objectName string) error {
if err := s3utils.CheckValidObjectName(objectName); err != nil {
return err
}
// Find multipart upload id of the object to be aborted.
uploadID, err := c.findUploadID(bucketName, objectName)
// Find multipart upload ids of the object to be aborted.
uploadIDs, err := c.findUploadIDs(bucketName, objectName)
if err != nil {
return err
}
if uploadID != "" {
// Upload id found, abort the incomplete multipart upload.

for _, uploadID := range uploadIDs {
// abort incomplete multipart upload, based on the upload id passed.
err := c.abortMultipartUpload(context.Background(), bucketName, objectName, uploadID)
if err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit f45f891

Please sign in to comment.