|
|
@ -23,6 +23,7 @@ import ( |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
|
|
mux "github.com/gorilla/mux" |
|
|
|
mux "github.com/gorilla/mux" |
|
|
|
"github.com/minio/minio-go/pkg/set" |
|
|
|
"github.com/minio/minio-go/pkg/set" |
|
|
@ -240,24 +241,41 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var deleteErrors []DeleteError |
|
|
|
var wg = &sync.WaitGroup{} // Allocate a new wait group.
|
|
|
|
|
|
|
|
var dErrs = make([]error, len(deleteObjects.Objects)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete all requested objects in parallel.
|
|
|
|
|
|
|
|
for index, object := range deleteObjects.Objects { |
|
|
|
|
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
go func(i int, obj ObjectIdentifier) { |
|
|
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
dErr := api.ObjectAPI.DeleteObject(bucket, obj.ObjectName) |
|
|
|
|
|
|
|
if dErr != nil { |
|
|
|
|
|
|
|
dErrs[i] = dErr |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}(index, object) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Collect deleted objects and errors if any.
|
|
|
|
var deletedObjects []ObjectIdentifier |
|
|
|
var deletedObjects []ObjectIdentifier |
|
|
|
// Loop through all the objects and delete them sequentially.
|
|
|
|
var deleteErrors []DeleteError |
|
|
|
for _, object := range deleteObjects.Objects { |
|
|
|
for index, err := range dErrs { |
|
|
|
err := api.ObjectAPI.DeleteObject(bucket, object.ObjectName) |
|
|
|
object := deleteObjects.Objects[index] |
|
|
|
|
|
|
|
// Success deleted objects are collected separately.
|
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|
deletedObjects = append(deletedObjects, ObjectIdentifier{ |
|
|
|
deletedObjects = append(deletedObjects, object) |
|
|
|
ObjectName: object.ObjectName, |
|
|
|
continue |
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
errorIf(err, "Unable to delete object.") |
|
|
|
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{ |
|
|
|
|
|
|
|
Code: errorCodeResponse[toAPIErrorCode(err)].Code, |
|
|
|
|
|
|
|
Message: errorCodeResponse[toAPIErrorCode(err)].Description, |
|
|
|
|
|
|
|
Key: object.ObjectName, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
errorIf(err, "Unable to delete object. %s", object.ObjectName) |
|
|
|
|
|
|
|
// Error during delete should be collected separately.
|
|
|
|
|
|
|
|
deleteErrors = append(deleteErrors, DeleteError{ |
|
|
|
|
|
|
|
Code: errorCodeResponse[toAPIErrorCode(err)].Code, |
|
|
|
|
|
|
|
Message: errorCodeResponse[toAPIErrorCode(err)].Description, |
|
|
|
|
|
|
|
Key: object.ObjectName, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generate response
|
|
|
|
// Generate response
|
|
|
|
response := generateMultiDeleteResponse(deleteObjects.Quiet, deletedObjects, deleteErrors) |
|
|
|
response := generateMultiDeleteResponse(deleteObjects.Quiet, deletedObjects, deleteErrors) |
|
|
|
encodedSuccessResponse := encodeResponse(response) |
|
|
|
encodedSuccessResponse := encodeResponse(response) |
|
|
@ -265,6 +283,22 @@ func (api objectAPIHandlers) DeleteMultipleObjectsHandler(w http.ResponseWriter, |
|
|
|
setCommonHeaders(w) |
|
|
|
setCommonHeaders(w) |
|
|
|
// Write success response.
|
|
|
|
// Write success response.
|
|
|
|
writeSuccessResponse(w, encodedSuccessResponse) |
|
|
|
writeSuccessResponse(w, encodedSuccessResponse) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if eventN.IsBucketNotificationSet(bucket) { |
|
|
|
|
|
|
|
// Notify deleted event for objects.
|
|
|
|
|
|
|
|
for _, dobj := range deletedObjects { |
|
|
|
|
|
|
|
eventNotify(eventData{ |
|
|
|
|
|
|
|
Type: ObjectRemovedDelete, |
|
|
|
|
|
|
|
Bucket: bucket, |
|
|
|
|
|
|
|
ObjInfo: ObjectInfo{ |
|
|
|
|
|
|
|
Name: dobj.ObjectName, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ReqParams: map[string]string{ |
|
|
|
|
|
|
|
"sourceIPAddress": r.RemoteAddr, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// PutBucketHandler - PUT Bucket
|
|
|
|
// PutBucketHandler - PUT Bucket
|
|
|
|