fs: fix logging by not logging common scenarios (#5882)

Fixes #5881
master
Harshavardhana 7 years ago committed by Nitish Tiwari
parent d6df9b16ac
commit d69ba7d085
  1. 37
      cmd/fs-v1-helpers.go
  2. 7
      cmd/fs-v1-rwpool.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
}

@ -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
}

Loading…
Cancel
Save