From d69ba7d085303955cd139dd9b9172e82d572c6be Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 2 May 2018 19:59:38 -0700 Subject: [PATCH] fs: fix logging by not logging common scenarios (#5882) Fixes #5881 --- cmd/fs-v1-helpers.go | 37 +++++++++++++++++++++---------------- cmd/fs-v1-rwpool.go | 7 +------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/fs-v1-helpers.go b/cmd/fs-v1-helpers.go index 94364305d..598fb8c02 100644 --- a/cmd/fs-v1-helpers.go +++ b/cmd/fs-v1-helpers.go @@ -42,14 +42,13 @@ func fsRemoveFile(ctx context.Context, filePath string) (err error) { } if err = os.Remove((filePath)); err != nil { - fsErr := osErrToFSFileErr(err) - if fsErr != errFileNotFound { + err = osErrToFSFileErr(err) + if err != errFileNotFound { logger.LogIf(ctx, err) } - return fsErr } - return nil + return err } // Removes all files and folders at a given path, handles @@ -95,10 +94,8 @@ func fsRemoveDir(ctx context.Context, dirPath string) (err error) { if err = os.Remove((dirPath)); err != nil { if os.IsNotExist(err) { - logger.LogIf(ctx, errVolumeNotFound) return errVolumeNotFound } else if isSysErrNotEmpty(err) { - logger.LogIf(ctx, errVolumeNotEmpty) return errVolumeNotEmpty } logger.LogIf(ctx, err) @@ -125,7 +122,6 @@ func fsMkdir(ctx context.Context, dirPath string) (err error) { if err = os.Mkdir((dirPath), 0777); err != nil { if os.IsExist(err) { - logger.LogIf(ctx, errVolumeExists) return errVolumeExists } else if os.IsPermission(err) { logger.LogIf(ctx, errDiskAccessDenied) @@ -161,11 +157,8 @@ func fsStat(ctx context.Context, statLoc string) (os.FileInfo, error) { logger.LogIf(ctx, err) return nil, err } - fi, err := os.Stat((statLoc)) + fi, err := os.Stat(statLoc) if err != nil { - if err != errFileNotFound { - logger.LogIf(ctx, err) - } return nil, err } @@ -219,9 +212,14 @@ func osErrToFSFileErr(err error) error { func fsStatDir(ctx context.Context, statDir string) (os.FileInfo, error) { fi, err := fsStat(ctx, statDir) if err != nil { - return nil, osErrToFSFileErr(err) + err = osErrToFSFileErr(err) + if err != errFileNotFound { + logger.LogIf(ctx, err) + } + return nil, err } if !fi.IsDir() { + logger.LogIf(ctx, errFileAccessDenied) return nil, errFileAccessDenied } return fi, nil @@ -231,7 +229,11 @@ func fsStatDir(ctx context.Context, statDir string) (os.FileInfo, error) { func fsStatFile(ctx context.Context, statFile string) (os.FileInfo, error) { fi, err := fsStat(ctx, statFile) if err != nil { - return nil, osErrToFSFileErr(err) + err = osErrToFSFileErr(err) + if err != errFileNotFound { + logger.LogIf(ctx, err) + } + return nil, err } if fi.IsDir() { logger.LogIf(ctx, errFileAccessDenied) @@ -252,15 +254,18 @@ func fsOpenFile(ctx context.Context, readPath string, offset int64) (io.ReadClos return nil, 0, err } - fr, err := os.Open((readPath)) + fr, err := os.Open(readPath) if err != nil { return nil, 0, osErrToFSFileErr(err) } // Stat to get the size of the file at path. - st, err := os.Stat((readPath)) + st, err := os.Stat(readPath) if err != nil { - logger.LogIf(ctx, err) + err = osErrToFSFileErr(err) + if err != errFileNotFound { + logger.LogIf(ctx, err) + } return nil, 0, err } diff --git a/cmd/fs-v1-rwpool.go b/cmd/fs-v1-rwpool.go index bf31518b2..38a7eb3a1 100644 --- a/cmd/fs-v1-rwpool.go +++ b/cmd/fs-v1-rwpool.go @@ -168,12 +168,7 @@ func (fsi *fsIOPool) Create(path string) (wlk *lock.LockedFile, err error) { } // Creates parent if missing. - if err = os.MkdirAll(pathutil.Dir(path), 0777); err != nil { - if os.IsPermission(err) { - return nil, errFileAccessDenied - } else if isSysErrNotDir(err) { - return nil, errFileAccessDenied - } + if err = mkdirAll(pathutil.Dir(path), 0777); err != nil { return nil, err }