func (self *Dispatcher) DeleteBucket(ctx api.ContextWithApi, bucketName string) *HTTPResponse { rollback, err := ctx.TxnBegin() if err != nil { ctx.Debugf("Failed to start transaction: %s", err) return HTTPInternalServerError } defer rollback() bucketApi := ctx.BucketApi() id, err := bucketApi.LookupIdByName(bucketName) if err != nil { return &HTTPResponse{Code: 500, Message: "Failed to find bucket"} } err = bucketApi.MarkForDelete(id) if err != nil { ctx.Debugf("Failed to delete bucket %s", err) return &HTTPResponse{Code: 500, Message: "Failed to delete bucket"} } if err = ctx.TxnCommit(); err != nil { ctx.Debugf("Failed to commit: %s", err) } else { ctx.Debugf("Deleted bucket '%s' (id = %d)", bucketName, id) } return HTTPNoContent }
func (self *Dispatcher) DeleteObject(ctx api.ContextWithApi, bucketName string, objectName string) *HTTPResponse { rollback, err := ctx.TxnBegin() if err != nil { ctx.Debugf("Failed to start transaction: %s", err) return HTTPInternalServerError } defer rollback() bucketApi := ctx.BucketApi() bucketId, err := bucketApi.LookupIdByName(bucketName) if err != nil { return &HTTPResponse{Code: 500, Message: "Failed to find bucket"} } bucketObj, err := bucketApi.Lookup(bucketId) if err != nil { return HTTPNotFound } if objectName == "" { return &HTTPResponse{Code: 500, Message: "Could not extact object name"} } objectApi := ctx.ObjectApi() objectId, err := objectApi.LookupIdByBucketAndPath(bucketObj, objectName) if err != nil { ctx.Debugf("Failed to lookup object %s/%s", bucketName, objectName) return HTTPNotFound } err = objectApi.MarkForDelete(objectId) if err != nil { ctx.Debugf("Failed to mark object (%d) as deleted: %s", objectId, err) return &HTTPResponse{Code: 500, Message: "Failed to mark object as deleted"} } err = ctx.TxnCommit() if err != nil { ctx.Debugf("Failed to commit: %s", err) return HTTPInternalServerError } ctx.Debugf("Successfully deleted object %s/%s", bucketName, objectName) go func() { queueApi := ctx.QueueApi() queueApi.Enqueue("queue_delete_object", strconv.FormatUint(objectId, 10)) }() return HTTPNoContent }