fs: Move traceError() to lower functions where possible. (#3633)

This commit is contained in:
Krishna Srinivas 2017-01-26 15:40:10 -08:00 committed by Harshavardhana
parent 17dd1c19df
commit 152cdf1c05
4 changed files with 100 additions and 98 deletions

View File

@ -27,20 +27,20 @@ import (
// windows automatically. // windows automatically.
func fsRemoveFile(filePath string) (err error) { func fsRemoveFile(filePath string) (err error) {
if filePath == "" { if filePath == "" {
return errInvalidArgument return traceError(errInvalidArgument)
} }
if err = checkPathLength(filePath); err != nil { if err = checkPathLength(filePath); err != nil {
return err return traceError(err)
} }
if err = os.Remove(preparePath(filePath)); err != nil { if err = os.Remove(preparePath(filePath)); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errFileNotFound return traceError(errFileNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return errFileAccessDenied return traceError(errFileAccessDenied)
} }
return err return traceError(err)
} }
return nil return nil
@ -50,43 +50,44 @@ func fsRemoveFile(filePath string) (err error) {
// long paths for windows automatically. // long paths for windows automatically.
func fsRemoveAll(dirPath string) (err error) { func fsRemoveAll(dirPath string) (err error) {
if dirPath == "" { if dirPath == "" {
return errInvalidArgument return traceError(errInvalidArgument)
} }
if err = checkPathLength(dirPath); err != nil { if err = checkPathLength(dirPath); err != nil {
return err return traceError(err)
} }
if err = removeAll(dirPath); err != nil { if err = removeAll(dirPath); err != nil {
if os.IsPermission(err) { if os.IsPermission(err) {
return errVolumeAccessDenied return traceError(errVolumeAccessDenied)
} }
return traceError(err)
} }
return err return nil
} }
// Removes a directory only if its empty, handles long // Removes a directory only if its empty, handles long
// paths for windows automatically. // paths for windows automatically.
func fsRemoveDir(dirPath string) (err error) { func fsRemoveDir(dirPath string) (err error) {
if dirPath == "" { if dirPath == "" {
return errInvalidArgument return traceError(errInvalidArgument)
} }
if err = checkPathLength(dirPath); err != nil { if err = checkPathLength(dirPath); err != nil {
return err return traceError(err)
} }
if err = os.Remove(preparePath(dirPath)); err != nil { if err = os.Remove(preparePath(dirPath)); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errVolumeNotFound return traceError(errVolumeNotFound)
} else if isSysErrNotEmpty(err) { } else if isSysErrNotEmpty(err) {
return errVolumeNotEmpty return traceError(errVolumeNotEmpty)
} }
return traceError(err)
} }
return err return nil
} }
// Creates a new directory, parent dir should exist // Creates a new directory, parent dir should exist
@ -95,26 +96,27 @@ func fsRemoveDir(dirPath string) (err error) {
// are handled automatically. // are handled automatically.
func fsMkdir(dirPath string) (err error) { func fsMkdir(dirPath string) (err error) {
if dirPath == "" { if dirPath == "" {
return errInvalidArgument return traceError(errInvalidArgument)
} }
if err = checkPathLength(dirPath); err != nil { if err = checkPathLength(dirPath); err != nil {
return err return traceError(err)
} }
if err = os.Mkdir(preparePath(dirPath), 0777); err != nil { if err = os.Mkdir(preparePath(dirPath), 0777); err != nil {
if os.IsExist(err) { if os.IsExist(err) {
return errVolumeExists return traceError(errVolumeExists)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return errDiskAccessDenied return traceError(errDiskAccessDenied)
} else if isSysErrNotDir(err) { } else if isSysErrNotDir(err) {
// File path cannot be verified since // File path cannot be verified since
// one of the parents is a file. // one of the parents is a file.
return errDiskAccessDenied return traceError(errDiskAccessDenied)
} else if isSysErrPathNotFound(err) { } else if isSysErrPathNotFound(err) {
// Add specific case for windows. // Add specific case for windows.
return errDiskAccessDenied return traceError(errDiskAccessDenied)
} }
return traceError(err)
} }
return nil return nil
@ -124,24 +126,24 @@ func fsMkdir(dirPath string) (err error) {
// attributes upon success. // attributes upon success.
func fsStatDir(statDir string) (os.FileInfo, error) { func fsStatDir(statDir string) (os.FileInfo, error) {
if statDir == "" { if statDir == "" {
return nil, errInvalidArgument return nil, traceError(errInvalidArgument)
} }
if err := checkPathLength(statDir); err != nil { if err := checkPathLength(statDir); err != nil {
return nil, err return nil, traceError(err)
} }
fi, err := os.Stat(preparePath(statDir)) fi, err := os.Stat(preparePath(statDir))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, errVolumeNotFound return nil, traceError(errVolumeNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return nil, errVolumeAccessDenied return nil, traceError(errVolumeAccessDenied)
} }
return nil, err return nil, traceError(err)
} }
if !fi.IsDir() { if !fi.IsDir() {
return nil, errVolumeAccessDenied return nil, traceError(errVolumeAccessDenied)
} }
return fi, nil return fi, nil
@ -150,28 +152,28 @@ func fsStatDir(statDir string) (os.FileInfo, error) {
// Lookup if file exists, returns file attributes upon success // Lookup if file exists, returns file attributes upon success
func fsStatFile(statFile string) (os.FileInfo, error) { func fsStatFile(statFile string) (os.FileInfo, error) {
if statFile == "" { if statFile == "" {
return nil, errInvalidArgument return nil, traceError(errInvalidArgument)
} }
if err := checkPathLength(statFile); err != nil { if err := checkPathLength(statFile); err != nil {
return nil, err return nil, traceError(err)
} }
fi, err := os.Stat(preparePath(statFile)) fi, err := os.Stat(preparePath(statFile))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, errFileNotFound return nil, traceError(errFileNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return nil, errFileAccessDenied return nil, traceError(errFileAccessDenied)
} else if isSysErrNotDir(err) { } else if isSysErrNotDir(err) {
return nil, errFileAccessDenied return nil, traceError(errFileAccessDenied)
} else if isSysErrPathNotFound(err) { } else if isSysErrPathNotFound(err) {
return nil, errFileNotFound return nil, traceError(errFileNotFound)
} }
return nil, err return nil, traceError(err)
} }
if fi.IsDir() { if fi.IsDir() {
return nil, errFileNotFound return nil, traceError(errFileNotFound)
} }
return fi, nil return fi, nil
} }
@ -180,44 +182,44 @@ func fsStatFile(statFile string) (os.FileInfo, error) {
// a readable stream and the size of the readable stream. // a readable stream and the size of the readable stream.
func fsOpenFile(readPath string, offset int64) (io.ReadCloser, int64, error) { func fsOpenFile(readPath string, offset int64) (io.ReadCloser, int64, error) {
if readPath == "" || offset < 0 { if readPath == "" || offset < 0 {
return nil, 0, errInvalidArgument return nil, 0, traceError(errInvalidArgument)
} }
if err := checkPathLength(readPath); err != nil { if err := checkPathLength(readPath); err != nil {
return nil, 0, err return nil, 0, traceError(err)
} }
fr, err := os.Open(preparePath(readPath)) fr, err := os.Open(preparePath(readPath))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil, 0, errFileNotFound return nil, 0, traceError(errFileNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return nil, 0, errFileAccessDenied return nil, 0, traceError(errFileAccessDenied)
} else if isSysErrNotDir(err) { } else if isSysErrNotDir(err) {
// File path cannot be verified since one of the parents is a file. // File path cannot be verified since one of the parents is a file.
return nil, 0, errFileAccessDenied return nil, 0, traceError(errFileAccessDenied)
} else if isSysErrPathNotFound(err) { } else if isSysErrPathNotFound(err) {
// Add specific case for windows. // Add specific case for windows.
return nil, 0, errFileNotFound return nil, 0, traceError(errFileNotFound)
} }
return nil, 0, err return nil, 0, traceError(err)
} }
// Stat to get the size of the file at path. // Stat to get the size of the file at path.
st, err := fr.Stat() st, err := fr.Stat()
if err != nil { if err != nil {
return nil, 0, err return nil, 0, traceError(err)
} }
// Verify if its not a regular file, since subsequent Seek is undefined. // Verify if its not a regular file, since subsequent Seek is undefined.
if !st.Mode().IsRegular() { if !st.Mode().IsRegular() {
return nil, 0, errIsNotRegular return nil, 0, traceError(errIsNotRegular)
} }
// Seek to the requested offset. // Seek to the requested offset.
if offset > 0 { if offset > 0 {
_, err = fr.Seek(offset, os.SEEK_SET) _, err = fr.Seek(offset, os.SEEK_SET)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, traceError(err)
} }
} }
@ -228,22 +230,22 @@ func fsOpenFile(readPath string, offset int64) (io.ReadCloser, int64, error) {
// Creates a file and copies data from incoming reader. Staging buffer is used by io.CopyBuffer. // Creates a file and copies data from incoming reader. Staging buffer is used by io.CopyBuffer.
func fsCreateFile(tempObjPath string, reader io.Reader, buf []byte, fallocSize int64) (int64, error) { func fsCreateFile(tempObjPath string, reader io.Reader, buf []byte, fallocSize int64) (int64, error) {
if tempObjPath == "" || reader == nil || buf == nil { if tempObjPath == "" || reader == nil || buf == nil {
return 0, errInvalidArgument return 0, traceError(errInvalidArgument)
} }
if err := checkPathLength(tempObjPath); err != nil { if err := checkPathLength(tempObjPath); err != nil {
return 0, err return 0, traceError(err)
} }
if err := mkdirAll(pathutil.Dir(tempObjPath), 0777); err != nil { if err := mkdirAll(pathutil.Dir(tempObjPath), 0777); err != nil {
return 0, err return 0, traceError(err)
} }
writer, err := os.OpenFile(preparePath(tempObjPath), os.O_CREATE|os.O_WRONLY, 0666) writer, err := os.OpenFile(preparePath(tempObjPath), os.O_CREATE|os.O_WRONLY, 0666)
if err != nil { if err != nil {
// File path cannot be verified since one of the parents is a file. // File path cannot be verified since one of the parents is a file.
if isSysErrNotDir(err) { if isSysErrNotDir(err) {
return 0, errFileAccessDenied return 0, traceError(errFileAccessDenied)
} }
return 0, err return 0, err
} }
@ -252,13 +254,13 @@ func fsCreateFile(tempObjPath string, reader io.Reader, buf []byte, fallocSize i
// Fallocate only if the size is final object is known. // Fallocate only if the size is final object is known.
if fallocSize > 0 { if fallocSize > 0 {
if err = fsFAllocate(int(writer.Fd()), 0, fallocSize); err != nil { if err = fsFAllocate(int(writer.Fd()), 0, fallocSize); err != nil {
return 0, err return 0, traceError(err)
} }
} }
bytesWritten, err := io.CopyBuffer(writer, reader, buf) bytesWritten, err := io.CopyBuffer(writer, reader, buf)
if err != nil { if err != nil {
return 0, err return 0, traceError(err)
} }
return bytesWritten, nil return bytesWritten, nil
@ -267,20 +269,20 @@ func fsCreateFile(tempObjPath string, reader io.Reader, buf []byte, fallocSize i
// Removes uploadID at destination path. // Removes uploadID at destination path.
func fsRemoveUploadIDPath(basePath, uploadIDPath string) error { func fsRemoveUploadIDPath(basePath, uploadIDPath string) error {
if basePath == "" || uploadIDPath == "" { if basePath == "" || uploadIDPath == "" {
return errInvalidArgument return traceError(errInvalidArgument)
} }
// List all the entries in uploadID. // List all the entries in uploadID.
entries, err := readDir(uploadIDPath) entries, err := readDir(uploadIDPath)
if err != nil && err != errFileNotFound { if err != nil && err != errFileNotFound {
return err return traceError(err)
} }
// Delete all the entries obtained from previous readdir. // Delete all the entries obtained from previous readdir.
for _, entryPath := range entries { for _, entryPath := range entries {
err = fsDeleteFile(basePath, pathJoin(uploadIDPath, entryPath)) err = fsDeleteFile(basePath, pathJoin(uploadIDPath, entryPath))
if err != nil && err != errFileNotFound { if err != nil && err != errFileNotFound {
return err return traceError(err)
} }
} }
@ -325,11 +327,11 @@ func fsRenameFile(sourcePath, destPath string) error {
// this function additionally protects the basePath from being deleted. // this function additionally protects the basePath from being deleted.
func fsDeleteFile(basePath, deletePath string) error { func fsDeleteFile(basePath, deletePath string) error {
if err := checkPathLength(basePath); err != nil { if err := checkPathLength(basePath); err != nil {
return err return traceError(err)
} }
if err := checkPathLength(deletePath); err != nil { if err := checkPathLength(deletePath); err != nil {
return err return traceError(err)
} }
if basePath == deletePath { if basePath == deletePath {
@ -340,11 +342,11 @@ func fsDeleteFile(basePath, deletePath string) error {
pathSt, err := os.Stat(preparePath(deletePath)) pathSt, err := os.Stat(preparePath(deletePath))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errFileNotFound return traceError(errFileNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return errFileAccessDenied return traceError(errFileAccessDenied)
} }
return err return traceError(err)
} }
if pathSt.IsDir() && !isDirEmpty(deletePath) { if pathSt.IsDir() && !isDirEmpty(deletePath) {
@ -355,13 +357,13 @@ func fsDeleteFile(basePath, deletePath string) error {
// Attempt to remove path. // Attempt to remove path.
if err = os.Remove(preparePath(deletePath)); err != nil { if err = os.Remove(preparePath(deletePath)); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return errFileNotFound return traceError(errFileNotFound)
} else if os.IsPermission(err) { } else if os.IsPermission(err) {
return errFileAccessDenied return traceError(errFileAccessDenied)
} else if isSysErrNotEmpty(err) { } else if isSysErrNotEmpty(err) {
return errVolumeNotEmpty return traceError(errVolumeNotEmpty)
} }
return err return traceError(err)
} }
// Recursively go down the next path and delete again. // Recursively go down the next path and delete again.

View File

@ -31,11 +31,11 @@ func TestFSStats(t *testing.T) {
// Setup test environment. // Setup test environment.
if err = fsMkdir(""); err != errInvalidArgument { if err = fsMkdir(""); errorCause(err) != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if err = fsMkdir(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); err != errFileNameTooLong { if err = fsMkdir(pathJoin(path, "my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001")); errorCause(err) != errFileNameTooLong {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -51,7 +51,7 @@ func TestFSStats(t *testing.T) {
// Seek back. // Seek back.
reader.Seek(0, 0) reader.Seek(0, 0)
if err = fsMkdir(pathJoin(path, "success-vol", "success-file")); err != errVolumeExists { if err = fsMkdir(pathJoin(path, "success-vol", "success-file")); errorCause(err) != errVolumeExists {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -138,11 +138,11 @@ func TestFSStats(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
if testCase.srcPath != "" { if testCase.srcPath != "" {
if _, err := fsStatFile(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { if _, err := fsStatFile(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); errorCause(err) != testCase.expectedErr {
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} else { } else {
if _, err := fsStatDir(pathJoin(testCase.srcFSPath, testCase.srcVol)); err != testCase.expectedErr { if _, err := fsStatDir(pathJoin(testCase.srcFSPath, testCase.srcVol)); errorCause(err) != testCase.expectedErr {
t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Fatalf("TestPosix case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
@ -161,11 +161,11 @@ func TestFSCreateAndOpen(t *testing.T) {
t.Fatalf("Unable to create directory, %s", err) t.Fatalf("Unable to create directory, %s", err)
} }
if _, err = fsCreateFile("", nil, nil, 0); err != errInvalidArgument { if _, err = fsCreateFile("", nil, nil, 0); errorCause(err) != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
if _, _, err = fsOpenFile("", -1); err != errInvalidArgument { if _, _, err = fsOpenFile("", -1); errorCause(err) != errInvalidArgument {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
@ -200,17 +200,17 @@ func TestFSCreateAndOpen(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
_, err = fsCreateFile(pathJoin(path, testCase.srcVol, testCase.srcPath), reader, buf, reader.Size()) _, err = fsCreateFile(pathJoin(path, testCase.srcVol, testCase.srcPath), reader, buf, reader.Size())
if err != testCase.expectedErr { if errorCause(err) != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
_, _, err = fsOpenFile(pathJoin(path, testCase.srcVol, testCase.srcPath), 0) _, _, err = fsOpenFile(pathJoin(path, testCase.srcVol, testCase.srcPath), 0)
if err != testCase.expectedErr { if errorCause(err) != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
// Attempt to open a directory. // Attempt to open a directory.
if _, _, err = fsOpenFile(pathJoin(path), 0); err != errIsNotRegular { if _, _, err = fsOpenFile(pathJoin(path), 0); errorCause(err) != errIsNotRegular {
t.Fatal("Unexpected error", err) t.Fatal("Unexpected error", err)
} }
} }
@ -272,7 +272,7 @@ func TestFSDeletes(t *testing.T) {
} }
for i, testCase := range testCases { for i, testCase := range testCases {
if err = fsDeleteFile(path, pathJoin(path, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { if err = fsDeleteFile(path, pathJoin(path, testCase.srcVol, testCase.srcPath)); errorCause(err) != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} }
@ -374,11 +374,11 @@ func TestFSRemoves(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
if testCase.srcPath != "" { if testCase.srcPath != "" {
if err = fsRemoveFile(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { if err = fsRemoveFile(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); errorCause(err) != testCase.expectedErr {
t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err) t.Errorf("Test case %d: Expected: \"%s\", got: \"%s\"", i+1, testCase.expectedErr, err)
} }
} else { } else {
if err = fsRemoveDir(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); err != testCase.expectedErr { if err = fsRemoveDir(pathJoin(testCase.srcFSPath, testCase.srcVol, testCase.srcPath)); errorCause(err) != testCase.expectedErr {
t.Error(err) t.Error(err)
} }
} }
@ -388,11 +388,11 @@ func TestFSRemoves(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRemoveAll(""); err != errInvalidArgument { if err = fsRemoveAll(""); errorCause(err) != errInvalidArgument {
t.Fatal(err) t.Fatal(err)
} }
if err = fsRemoveAll("my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); err != errFileNameTooLong { if err = fsRemoveAll("my-obj-del-0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"); errorCause(err) != errFileNameTooLong {
t.Fatal(err) t.Fatal(err)
} }
} }

View File

@ -633,7 +633,7 @@ func (fs fsObjects) listObjectParts(bucket, object, uploadID string, partNumberM
partNamePath := pathJoin(fs.fsPath, minioMetaMultipartBucket, uploadIDPath, part.Name) partNamePath := pathJoin(fs.fsPath, minioMetaMultipartBucket, uploadIDPath, part.Name)
fi, err = fsStatFile(partNamePath) fi, err = fsStatFile(partNamePath)
if err != nil { if err != nil {
return ListPartsInfo{}, toObjectErr(traceError(err), minioMetaMultipartBucket, partNamePath) return ListPartsInfo{}, toObjectErr(err, minioMetaMultipartBucket, partNamePath)
} }
result.Parts = append(result.Parts, partInfo{ result.Parts = append(result.Parts, partInfo{
PartNumber: part.Number, PartNumber: part.Number,
@ -883,7 +883,7 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload
multipartObjectDir := pathJoin(fs.fsPath, minioMetaMultipartBucket, bucket, object) multipartObjectDir := pathJoin(fs.fsPath, minioMetaMultipartBucket, bucket, object)
multipartUploadIDDir := pathJoin(multipartObjectDir, uploadID) multipartUploadIDDir := pathJoin(multipartObjectDir, uploadID)
if err = fsRemoveUploadIDPath(multipartObjectDir, multipartUploadIDDir); err != nil { if err = fsRemoveUploadIDPath(multipartObjectDir, multipartUploadIDDir); err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), bucket, object) return ObjectInfo{}, toObjectErr(err, bucket, object)
} }
// Remove entry from `uploads.json`. // Remove entry from `uploads.json`.
@ -893,7 +893,7 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload
fi, err := fsStatFile(fsNSObjPath) fi, err := fsStatFile(fsNSObjPath)
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), bucket, object) return ObjectInfo{}, toObjectErr(err, bucket, object)
} }
// Return object info. // Return object info.
@ -961,7 +961,7 @@ func (fs fsObjects) AbortMultipartUpload(bucket, object, uploadID string) error
multipartObjectDir := pathJoin(fs.fsPath, minioMetaMultipartBucket, bucket, object) multipartObjectDir := pathJoin(fs.fsPath, minioMetaMultipartBucket, bucket, object)
multipartUploadIDDir := pathJoin(multipartObjectDir, uploadID) multipartUploadIDDir := pathJoin(multipartObjectDir, uploadID)
if err = fsRemoveUploadIDPath(multipartObjectDir, multipartUploadIDDir); err != nil { if err = fsRemoveUploadIDPath(multipartObjectDir, multipartUploadIDDir); err != nil {
return toObjectErr(traceError(err), bucket, object) return toObjectErr(err, bucket, object)
} }
// Remove entry from `uploads.json`. // Remove entry from `uploads.json`.

View File

@ -245,7 +245,7 @@ func (fs fsObjects) statBucketDir(bucket string) (os.FileInfo, error) {
} }
st, err := fsStatDir(bucketDir) st, err := fsStatDir(bucketDir)
if err != nil { if err != nil {
return nil, traceError(err) return nil, err
} }
return st, nil return st, nil
} }
@ -259,7 +259,7 @@ func (fs fsObjects) MakeBucket(bucket string) error {
} }
if err = fsMkdir(bucketDir); err != nil { if err = fsMkdir(bucketDir); err != nil {
return toObjectErr(traceError(err), bucket) return toObjectErr(err, bucket)
} }
return nil return nil
@ -283,7 +283,7 @@ func (fs fsObjects) GetBucketInfo(bucket string) (BucketInfo, error) {
// ListBuckets - list all s3 compatible buckets (directories) at fsPath. // ListBuckets - list all s3 compatible buckets (directories) at fsPath.
func (fs fsObjects) ListBuckets() ([]BucketInfo, error) { func (fs fsObjects) ListBuckets() ([]BucketInfo, error) {
if err := checkPathLength(fs.fsPath); err != nil { if err := checkPathLength(fs.fsPath); err != nil {
return nil, err return nil, traceError(err)
} }
var bucketInfos []BucketInfo var bucketInfos []BucketInfo
entries, err := readDir(preparePath(fs.fsPath)) entries, err := readDir(preparePath(fs.fsPath))
@ -301,9 +301,9 @@ func (fs fsObjects) ListBuckets() ([]BucketInfo, error) {
fi, err = fsStatDir(pathJoin(fs.fsPath, entry)) fi, err = fsStatDir(pathJoin(fs.fsPath, entry))
if err != nil { if err != nil {
// If the directory does not exist, skip the entry. // If the directory does not exist, skip the entry.
if err == errVolumeNotFound { if errorCause(err) == errVolumeNotFound {
continue continue
} else if err == errVolumeAccessDenied { } else if errorCause(err) == errVolumeAccessDenied {
// Skip the entry if its a file. // Skip the entry if its a file.
continue continue
} }
@ -376,7 +376,7 @@ func (fs fsObjects) CopyObject(srcBucket, srcObject, dstBucket, dstObject string
// Stat the file to get file size. // Stat the file to get file size.
fi, err := fsStatFile(pathJoin(fs.fsPath, srcBucket, srcObject)) fi, err := fsStatFile(pathJoin(fs.fsPath, srcBucket, srcObject))
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), srcBucket, srcObject) return ObjectInfo{}, toObjectErr(err, srcBucket, srcObject)
} }
// Check if this request is only metadata update. // Check if this request is only metadata update.
@ -386,7 +386,7 @@ func (fs fsObjects) CopyObject(srcBucket, srcObject, dstBucket, dstObject string
var wlk *lock.LockedFile var wlk *lock.LockedFile
wlk, err = fs.rwPool.Write(fsMetaPath) wlk, err = fs.rwPool.Write(fsMetaPath)
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(err, srcBucket, srcObject) return ObjectInfo{}, toObjectErr(traceError(err), srcBucket, srcObject)
} }
// This close will allow for locks to be synchronized on `fs.json`. // This close will allow for locks to be synchronized on `fs.json`.
defer wlk.Close() defer wlk.Close()
@ -467,7 +467,7 @@ func (fs fsObjects) GetObject(bucket, object string, offset int64, length int64,
fsObjPath := pathJoin(fs.fsPath, bucket, object) fsObjPath := pathJoin(fs.fsPath, bucket, object)
reader, size, err := fsOpenFile(fsObjPath, offset) reader, size, err := fsOpenFile(fsObjPath, offset)
if err != nil { if err != nil {
return toObjectErr(traceError(err), bucket, object) return toObjectErr(err, bucket, object)
} }
defer reader.Close() defer reader.Close()
@ -523,7 +523,7 @@ func (fs fsObjects) getObjectInfo(bucket, object string) (ObjectInfo, error) {
// Stat the file to get file size. // Stat the file to get file size.
fi, err := fsStatFile(pathJoin(fs.fsPath, bucket, object)) fi, err := fsStatFile(pathJoin(fs.fsPath, bucket, object))
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), bucket, object) return ObjectInfo{}, toObjectErr(err, bucket, object)
} }
return fsMeta.ToObjectInfo(bucket, object, fi), nil return fsMeta.ToObjectInfo(bucket, object, fi), nil
@ -574,7 +574,7 @@ func (fs fsObjects) PutObject(bucket string, object string, size int64, data io.
fsMetaPath := pathJoin(fs.fsPath, minioMetaBucket, bucketMetaPrefix, bucket, object, fsMetaJSONFile) fsMetaPath := pathJoin(fs.fsPath, minioMetaBucket, bucketMetaPrefix, bucket, object, fsMetaJSONFile)
wlk, err = fs.rwPool.Create(fsMetaPath) wlk, err = fs.rwPool.Create(fsMetaPath)
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(err, bucket, object) return ObjectInfo{}, toObjectErr(traceError(err), bucket, object)
} }
// This close will allow for locks to be synchronized on `fs.json`. // This close will allow for locks to be synchronized on `fs.json`.
defer wlk.Close() defer wlk.Close()
@ -672,7 +672,7 @@ func (fs fsObjects) PutObject(bucket string, object string, size int64, data io.
// Stat the file to fetch timestamp, size. // Stat the file to fetch timestamp, size.
fi, err := fsStatFile(pathJoin(fs.fsPath, bucket, object)) fi, err := fsStatFile(pathJoin(fs.fsPath, bucket, object))
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), bucket, object) return ObjectInfo{}, toObjectErr(err, bucket, object)
} }
// Success. // Success.
@ -699,20 +699,20 @@ func (fs fsObjects) DeleteObject(bucket, object string) error {
defer rwlk.Close() defer rwlk.Close()
} }
if lerr != nil && lerr != errFileNotFound { if lerr != nil && lerr != errFileNotFound {
return toObjectErr(lerr, bucket, object) return toObjectErr(traceError(lerr), bucket, object)
} }
} }
// Delete the object. // Delete the object.
if err := fsDeleteFile(pathJoin(fs.fsPath, bucket), pathJoin(fs.fsPath, bucket, object)); err != nil { if err := fsDeleteFile(pathJoin(fs.fsPath, bucket), pathJoin(fs.fsPath, bucket, object)); err != nil {
return toObjectErr(traceError(err), bucket, object) return toObjectErr(err, bucket, object)
} }
if bucket != minioMetaBucket { if bucket != minioMetaBucket {
// Delete the metadata object. // Delete the metadata object.
err := fsDeleteFile(minioMetaBucketDir, fsMetaPath) err := fsDeleteFile(minioMetaBucketDir, fsMetaPath)
if err != nil && err != errFileNotFound { if err != nil && errorCause(err) != errFileNotFound {
return toObjectErr(traceError(err), bucket, object) return toObjectErr(err, bucket, object)
} }
} }
return nil return nil
@ -790,7 +790,7 @@ func (fs fsObjects) ListObjects(bucket, prefix, marker, delimiter string, maxKey
var fi os.FileInfo var fi os.FileInfo
fi, err = fsStatFile(pathJoin(fs.fsPath, bucket, entry)) fi, err = fsStatFile(pathJoin(fs.fsPath, bucket, entry))
if err != nil { if err != nil {
return ObjectInfo{}, toObjectErr(traceError(err), bucket, entry) return ObjectInfo{}, toObjectErr(err, bucket, entry)
} }
fsMeta := fsMetaV1{} fsMeta := fsMetaV1{}
return fsMeta.ToObjectInfo(bucket, entry, fi), nil return fsMeta.ToObjectInfo(bucket, entry, fi), nil