diff --git a/cmd/server-main.go b/cmd/server-main.go index bf18c72c4..e75b9ca11 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -37,6 +37,7 @@ func init() { logger.Init(GOPATH, GOROOT) logger.RegisterUIError(fmtError) gob.Register(HashMismatchError{}) + gob.Register(DeleteFileError("")) } // ServerFlags - server command specific flags diff --git a/cmd/storage-rest-client.go b/cmd/storage-rest-client.go index c7bf92671..a12157b3f 100644 --- a/cmd/storage-rest-client.go +++ b/cmd/storage-rest-client.go @@ -375,7 +375,6 @@ func (client *storageRESTClient) DeleteFileBulk(volume string, paths []string) ( if len(paths) == 0 { return errs, err } - errs = make([]error, len(paths)) values := make(url.Values) values.Set(storageRESTVolume, volume) for _, path := range paths { @@ -388,14 +387,13 @@ func (client *storageRESTClient) DeleteFileBulk(volume string, paths []string) ( return nil, err } - bulkErrs := bulkErrorsResponse{} - gob.NewDecoder(respBody).Decode(&bulkErrs) - if err != nil { + dErrResp := &DeleteFileBulkErrsResp{} + if err = gob.NewDecoder(respBody).Decode(dErrResp); err != nil { return nil, err } - for i, dErr := range bulkErrs.Errs { - errs[i] = toStorageErr(dErr) + for _, dErr := range dErrResp.Errs { + errs = append(errs, toStorageErr(dErr)) } return errs, nil diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index 924b82b5c..98dd90a08 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -49,22 +49,6 @@ func (s *storageRESTServer) writeErrorResponse(w http.ResponseWriter, err error) w.(http.Flusher).Flush() } -type bulkErrorsResponse struct { - Errs []error `json:"errors"` -} - -func (s *storageRESTServer) writeErrorsResponse(w http.ResponseWriter, errs []error) { - resp := bulkErrorsResponse{Errs: make([]error, len(errs))} - for idx, err := range errs { - if err == nil { - continue - } - resp.Errs[idx] = err - } - gob.NewEncoder(w).Encode(resp) - w.(http.Flusher).Flush() -} - // DefaultSkewTime - skew time is 15 minutes between minio peers. const DefaultSkewTime = 15 * time.Minute @@ -455,6 +439,19 @@ func (s *storageRESTServer) DeleteFileHandler(w http.ResponseWriter, r *http.Req } } +// DeleteFileBulkErrsResp - collection of deleteFile errors +// for bulk deletes +type DeleteFileBulkErrsResp struct { + Errs []error +} + +// DeleteFileError - error captured per delete operation +type DeleteFileError string + +func (d DeleteFileError) Error() string { + return string(d) +} + // DeleteFileBulkHandler - delete a file. func (s *storageRESTServer) DeleteFileBulkHandler(w http.ResponseWriter, r *http.Request) { if !s.IsValid(w, r) { @@ -470,7 +467,15 @@ func (s *storageRESTServer) DeleteFileBulkHandler(w http.ResponseWriter, r *http return } - s.writeErrorsResponse(w, errs) + derrsResp := &DeleteFileBulkErrsResp{Errs: make([]error, len(errs))} + for idx, err := range errs { + if err != nil { + derrsResp.Errs[idx] = DeleteFileError(err.Error()) + } + } + + gob.NewEncoder(w).Encode(derrsResp) + w.(http.Flusher).Flush() } // RenameFileHandler - rename a file.