From df931022353b5ecb899c77c928550e6d426bf161 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 23 Nov 2020 08:36:49 -0800 Subject: [PATCH] fix: unwrapping issues with os.Is* functions (#10949) reduces 3 stat calls, reducing the overall startup time significantly. --- cmd/config-dir.go | 2 +- cmd/config-migrate.go | 62 ++++++++-------- cmd/config-migrate_test.go | 2 +- cmd/data-update-tracker.go | 4 +- cmd/disk-cache-backend.go | 2 +- cmd/fastwalk.go | 2 +- cmd/format-disk-cache.go | 4 +- cmd/format-erasure.go | 16 ++-- cmd/format-fs.go | 4 +- cmd/fs-v1-helpers.go | 16 ++-- cmd/fs-v1-helpers_test.go | 4 +- cmd/fs-v1-rwpool.go | 10 +-- cmd/fs-v1.go | 2 +- cmd/metacache-walk.go | 4 +- cmd/object-api-putobject_test.go | 2 +- cmd/os-readdir_unix.go | 2 +- cmd/os-reliable.go | 12 +-- cmd/prepare-storage.go | 28 ++----- cmd/storage-errors.go | 6 +- cmd/update.go | 6 +- cmd/xl-storage-errors.go | 12 +++ cmd/xl-storage.go | 122 +++++++++++++++---------------- 22 files changed, 158 insertions(+), 166 deletions(-) diff --git a/cmd/config-dir.go b/cmd/config-dir.go index c76ed30ea..7f8426e8c 100644 --- a/cmd/config-dir.go +++ b/cmd/config-dir.go @@ -87,7 +87,7 @@ func mkdirAllIgnorePerm(path string) error { if err != nil { // It is possible in kubernetes like deployments this directory // is already mounted and is not writable, ignore any write errors. - if os.IsPermission(err) { + if osIsPermission(err) { err = nil } } diff --git a/cmd/config-migrate.go b/cmd/config-migrate.go index 3fe23cfae..f9ecbf9ec 100644 --- a/cmd/config-migrate.go +++ b/cmd/config-migrate.go @@ -74,7 +74,7 @@ func migrateConfig() error { // Load only config version information. version, err := GetVersion(getConfigFile()) if err != nil { - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } return err @@ -243,7 +243,7 @@ func purgeV1() error { cv1 := &configV1{} _, err := Load(configFile, cv1) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘1’. %w", err) @@ -264,7 +264,7 @@ func migrateV2ToV3() error { cv2 := &configV2{} _, err := Load(configFile, cv2) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘2’. %w", err) @@ -323,7 +323,7 @@ func migrateV3ToV4() error { cv3 := &configV3{} _, err := Load(configFile, cv3) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘3’. %w", err) @@ -361,7 +361,7 @@ func migrateV4ToV5() error { cv4 := &configV4{} _, err := Load(configFile, cv4) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘4’. %w", err) @@ -402,7 +402,7 @@ func migrateV5ToV6() error { cv5 := &configV5{} _, err := Load(configFile, cv5) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘5’. %w", err) @@ -491,7 +491,7 @@ func migrateV6ToV7() error { cv6 := &configV6{} _, err := Load(configFile, cv6) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘6’. %w", err) @@ -547,7 +547,7 @@ func migrateV7ToV8() error { cv7 := &serverConfigV7{} _, err := Load(configFile, cv7) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘7’. %w", err) @@ -609,7 +609,7 @@ func migrateV8ToV9() error { cv8 := &serverConfigV8{} _, err := Load(configFile, cv8) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘8’. %w", err) @@ -679,7 +679,7 @@ func migrateV9ToV10() error { cv9 := &serverConfigV9{} _, err := Load(configFile, cv9) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘9’. %w", err) @@ -747,7 +747,7 @@ func migrateV10ToV11() error { cv10 := &serverConfigV10{} _, err := Load(configFile, cv10) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘10’. %w", err) @@ -818,7 +818,7 @@ func migrateV11ToV12() error { cv11 := &serverConfigV11{} _, err := Load(configFile, cv11) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘11’. %w", err) @@ -915,7 +915,7 @@ func migrateV12ToV13() error { cv12 := &serverConfigV12{} _, err := Load(configFile, cv12) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘12’. %w", err) @@ -995,7 +995,7 @@ func migrateV13ToV14() error { cv13 := &serverConfigV13{} _, err := Load(configFile, cv13) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘13’. %w", err) @@ -1080,7 +1080,7 @@ func migrateV14ToV15() error { cv14 := &serverConfigV14{} _, err := Load(configFile, cv14) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘14’. %w", err) @@ -1170,7 +1170,7 @@ func migrateV15ToV16() error { cv15 := &serverConfigV15{} _, err := Load(configFile, cv15) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘15’. %w", err) @@ -1260,7 +1260,7 @@ func migrateV16ToV17() error { cv16 := &serverConfigV16{} _, err := Load(configFile, cv16) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘16’. %w", err) @@ -1381,7 +1381,7 @@ func migrateV17ToV18() error { cv17 := &serverConfigV17{} _, err := Load(configFile, cv17) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘17’. %w", err) @@ -1483,7 +1483,7 @@ func migrateV18ToV19() error { cv18 := &serverConfigV18{} _, err := Load(configFile, cv18) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘18’. %w", err) @@ -1589,7 +1589,7 @@ func migrateV19ToV20() error { cv19 := &serverConfigV19{} _, err := Load(configFile, cv19) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘18’. %w", err) @@ -1694,7 +1694,7 @@ func migrateV20ToV21() error { cv20 := &serverConfigV20{} _, err := Load(configFile, cv20) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘20’. %w", err) @@ -1798,7 +1798,7 @@ func migrateV21ToV22() error { cv21 := &serverConfigV21{} _, err := Load(configFile, cv21) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘21’. %w", err) @@ -1902,7 +1902,7 @@ func migrateV22ToV23() error { cv22 := &serverConfigV22{} _, err := Load(configFile, cv22) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘22’. %w", err) @@ -2015,7 +2015,7 @@ func migrateV23ToV24() error { cv23 := &serverConfigV23{} _, err := quick.LoadConfig(configFile, globalEtcdClient, cv23) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘23’. %w", err) @@ -2128,7 +2128,7 @@ func migrateV24ToV25() error { cv24 := &serverConfigV24{} _, err := quick.LoadConfig(configFile, globalEtcdClient, cv24) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘24’. %w", err) @@ -2246,7 +2246,7 @@ func migrateV25ToV26() error { cv25 := &serverConfigV25{} _, err := quick.LoadConfig(configFile, globalEtcdClient, cv25) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config version ‘25’. %w", err) @@ -2368,7 +2368,7 @@ func migrateV26ToV27() error { // in the new `logger` field srvConfig := &serverConfigV27{} _, err := quick.LoadConfig(configFile, globalEtcdClient, srvConfig) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config file. %w", err) @@ -2401,7 +2401,7 @@ func migrateV27ToV28() error { srvConfig := &serverConfigV28{} _, err := quick.LoadConfig(configFile, globalEtcdClient, srvConfig) - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { return nil } else if err != nil { return fmt.Errorf("Unable to load config file. %w", err) @@ -2452,17 +2452,17 @@ func migrateConfigToMinioSys(objAPI ObjectLayer) (err error) { var config = &serverConfigV27{} for _, cfgFile := range configFiles { if _, err = Load(cfgFile, config); err != nil { - if !os.IsNotExist(err) && !os.IsPermission(err) { + if !osIsNotExist(err) && !osIsPermission(err) { return err } continue } break } - if os.IsPermission(err) { + if osIsPermission(err) { logger.Info("Older config found but not readable %s, proceeding to initialize new config anyways", err) } - if os.IsNotExist(err) || os.IsPermission(err) { + if osIsNotExist(err) || osIsPermission(err) { // Initialize the server config, if no config exists. return newSrvConfig(objAPI) } diff --git a/cmd/config-migrate_test.go b/cmd/config-migrate_test.go index 5cd087b30..cc5da0030 100644 --- a/cmd/config-migrate_test.go +++ b/cmd/config-migrate_test.go @@ -60,7 +60,7 @@ func TestServerConfigMigrateV1(t *testing.T) { } // Check if config v1 is removed from filesystem - if _, err := os.Stat(configPath); err == nil || !os.IsNotExist(err) { + if _, err := os.Stat(configPath); err == nil || !osIsNotExist(err) { t.Fatal("Config V1 file is not purged") } diff --git a/cmd/data-update-tracker.go b/cmd/data-update-tracker.go index 91751f278..15cd1cd32 100644 --- a/cmd/data-update-tracker.go +++ b/cmd/data-update-tracker.go @@ -235,7 +235,7 @@ func (d *dataUpdateTracker) load(ctx context.Context, drives ...string) { cacheFormatPath := pathJoin(drive, dataUpdateTrackerFilename) f, err := os.Open(cacheFormatPath) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { continue } logger.LogIf(ctx, err) @@ -300,7 +300,7 @@ func (d *dataUpdateTracker) startSaver(ctx context.Context, interval time.Durati cacheFormatPath := pathJoin(drive, dataUpdateTrackerFilename) err := ioutil.WriteFile(cacheFormatPath, buf.Bytes(), os.ModePerm) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { continue } logger.LogIf(ctx, err) diff --git a/cmd/disk-cache-backend.go b/cmd/disk-cache-backend.go index 12ab49707..fc9759e67 100644 --- a/cmd/disk-cache-backend.go +++ b/cmd/disk-cache-backend.go @@ -704,7 +704,7 @@ func (c *diskCache) Put(ctx context.Context, bucket, object string, data io.Read meta, _, numHits, err := c.statCache(ctx, cachePath) // Case where object not yet cached - if os.IsNotExist(err) && c.after >= 1 { + if osIsNotExist(err) && c.after >= 1 { return oi, c.saveMetadata(ctx, bucket, object, opts.UserDefined, size, nil, "", false) } // Case where object already has a cache metadata entry but not yet cached diff --git a/cmd/fastwalk.go b/cmd/fastwalk.go index 2096982e6..ba1806e55 100644 --- a/cmd/fastwalk.go +++ b/cmd/fastwalk.go @@ -19,7 +19,7 @@ var errSkipFile = errors.New("fastwalk: skip this file") func readDirFn(dirName string, fn func(entName string, typ os.FileMode) error) error { fis, err := readDir(dirName) if err != nil { - if os.IsNotExist(err) || err == errFileNotFound { + if osIsNotExist(err) || err == errFileNotFound { return nil } return err diff --git a/cmd/format-disk-cache.go b/cmd/format-disk-cache.go index 5b064bcf2..219cd677b 100644 --- a/cmd/format-disk-cache.go +++ b/cmd/format-disk-cache.go @@ -157,7 +157,7 @@ func loadFormatCache(ctx context.Context, drives []string) ([]*formatCacheV2, bo f, err := os.OpenFile(cacheFormatPath, os.O_RDWR, 0) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { continue } logger.LogIf(ctx, err) @@ -318,7 +318,7 @@ func cacheDrivesUnformatted(drives []string) bool { count := 0 for _, drive := range drives { cacheFormatPath := pathJoin(drive, minioMetaBucket, formatConfigFile) - if _, err := os.Stat(cacheFormatPath); os.IsNotExist(err) { + if _, err := os.Stat(cacheFormatPath); osIsNotExist(err) { count++ } } diff --git a/cmd/format-erasure.go b/cmd/format-erasure.go index bce86e914..ca06e7531 100644 --- a/cmd/format-erasure.go +++ b/cmd/format-erasure.go @@ -167,7 +167,7 @@ func formatGetBackendErasureVersion(formatPath string) (string, error) { return "", fmt.Errorf(`format.Version expected: %s, got: %s`, formatMetaVersionV1, meta.Version) } if meta.Format != formatBackendErasure { - return "", fmt.Errorf(`found backend %s, expected %s`, meta.Format, formatBackendErasure) + return "", fmt.Errorf(`found backend type %s, expected %s`, meta.Format, formatBackendErasure) } // Erasure backend found, proceed to detect version. format := &formatErasureVersionDetect{} @@ -179,24 +179,24 @@ func formatGetBackendErasureVersion(formatPath string) (string, error) { // Migrates all previous versions to latest version of `format.json`, // this code calls migration in sequence, such as V1 is migrated to V2 -// first before it V2 migrates to V3. +// first before it V2 migrates to V3.n func formatErasureMigrate(export string) error { formatPath := pathJoin(export, minioMetaBucket, formatConfigFile) version, err := formatGetBackendErasureVersion(formatPath) if err != nil { - return err + return fmt.Errorf("Disk %s: %w", export, err) } switch version { case formatErasureVersionV1: if err = formatErasureMigrateV1ToV2(export, version); err != nil { - return err + return fmt.Errorf("Disk %s: %w", export, err) } // Migrate successful v1 => v2, proceed to v2 => v3 version = formatErasureVersionV2 fallthrough case formatErasureVersionV2: if err = formatErasureMigrateV2ToV3(export, version); err != nil { - return err + return fmt.Errorf("Disk %s: %w", export, err) } // Migrate successful v2 => v3, v3 is latest // version = formatXLVersionV3 @@ -205,14 +205,14 @@ func formatErasureMigrate(export string) error { // v3 is the latest version, return. return nil } - return fmt.Errorf(`%s: unknown format version %s`, export, version) + return fmt.Errorf(`Disk %s: unknown format version %s`, export, version) } // Migrates version V1 of format.json to version V2 of format.json, // migration fails upon any error. func formatErasureMigrateV1ToV2(export, version string) error { if version != formatErasureVersionV1 { - return fmt.Errorf(`Disk %s: format version expected %s, found %s`, export, formatErasureVersionV1, version) + return fmt.Errorf(`format version expected %s, found %s`, formatErasureVersionV1, version) } formatPath := pathJoin(export, minioMetaBucket, formatConfigFile) @@ -246,7 +246,7 @@ func formatErasureMigrateV1ToV2(export, version string) error { // Migrates V2 for format.json to V3 (Flat hierarchy for multipart) func formatErasureMigrateV2ToV3(export, version string) error { if version != formatErasureVersionV2 { - return fmt.Errorf(`Disk %s: format version expected %s, found %s`, export, formatErasureVersionV2, version) + return fmt.Errorf(`format version expected %s, found %s`, formatErasureVersionV2, version) } formatPath := pathJoin(export, minioMetaBucket, formatConfigFile) diff --git a/cmd/format-fs.go b/cmd/format-fs.go index 46952f171..fd242dd4e 100644 --- a/cmd/format-fs.go +++ b/cmd/format-fs.go @@ -211,7 +211,7 @@ func initFormatFS(ctx context.Context, fsPath string) (rlk *lock.RLockedFile, er } isEmpty = fi.Size() == 0 } - if os.IsNotExist(err) || isEmpty { + if osIsNotExist(err) || isEmpty { if err == nil { rlk.Close() } @@ -306,7 +306,7 @@ func formatFSFixDeploymentID(ctx context.Context, fsFormatPath string) error { return nil } } - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil } if err != nil { diff --git a/cmd/fs-v1-helpers.go b/cmd/fs-v1-helpers.go index 2fb42c694..7009a3ed0 100644 --- a/cmd/fs-v1-helpers.go +++ b/cmd/fs-v1-helpers.go @@ -64,7 +64,7 @@ func fsRemoveAll(ctx context.Context, dirPath string) (err error) { } if err = removeAll(dirPath); err != nil { - if os.IsPermission(err) { + if osIsPermission(err) { logger.LogIf(ctx, errVolumeAccessDenied) return errVolumeAccessDenied } else if isSysErrNotEmpty(err) { @@ -92,7 +92,7 @@ func fsRemoveDir(ctx context.Context, dirPath string) (err error) { } if err = os.Remove((dirPath)); err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrNotEmpty(err) { return errVolumeNotEmpty @@ -121,9 +121,9 @@ func fsMkdir(ctx context.Context, dirPath string) (err error) { if err = os.Mkdir((dirPath), 0777); err != nil { switch { - case os.IsExist(err): + case osIsExist(err): return errVolumeExists - case os.IsPermission(err): + case osIsPermission(err): logger.LogIf(ctx, errDiskAccessDenied) return errDiskAccessDenied case isSysErrNotDir(err): @@ -170,9 +170,9 @@ func fsStat(ctx context.Context, statLoc string) (os.FileInfo, error) { func fsStatVolume(ctx context.Context, volume string) (os.FileInfo, error) { fi, err := fsStat(ctx, volume) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return nil, errVolumeAccessDenied } return nil, err @@ -285,9 +285,9 @@ func fsCreateFile(ctx context.Context, filePath string, reader io.Reader, buf [] if err := mkdirAll(pathutil.Dir(filePath), 0777); err != nil { switch { - case os.IsPermission(err): + case osIsPermission(err): return 0, errFileAccessDenied - case os.IsExist(err): + case osIsExist(err): return 0, errFileAccessDenied case isSysErrIO(err): return 0, errFaultyDisk diff --git a/cmd/fs-v1-helpers_test.go b/cmd/fs-v1-helpers_test.go index 21c8be76e..8344b913d 100644 --- a/cmd/fs-v1-helpers_test.go +++ b/cmd/fs-v1-helpers_test.go @@ -538,11 +538,11 @@ func TestFSRemoveMeta(t *testing.T) { t.Fatalf("Unable to remove file, %s", err) } - if _, err := os.Stat((filePath)); !os.IsNotExist(err) { + if _, err := os.Stat((filePath)); !osIsNotExist(err) { t.Fatalf("`%s` file found though it should have been deleted.", filePath) } - if _, err := os.Stat((path.Dir(filePath))); !os.IsNotExist(err) { + if _, err := os.Stat((path.Dir(filePath))); !osIsNotExist(err) { t.Fatalf("`%s` parent directory found though it should have been deleted.", filePath) } } diff --git a/cmd/fs-v1-rwpool.go b/cmd/fs-v1-rwpool.go index 3d1e3dff1..0691828c8 100644 --- a/cmd/fs-v1-rwpool.go +++ b/cmd/fs-v1-rwpool.go @@ -93,9 +93,9 @@ func (fsi *fsIOPool) Open(path string) (*lock.RLockedFile, error) { newRlkFile, err := lock.RLockedOpenFile(path) if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return nil, errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrIsDir(err): return nil, errIsNotRegular @@ -150,9 +150,9 @@ func (fsi *fsIOPool) Write(path string) (wlk *lock.LockedFile, err error) { wlk, err = lock.LockedOpenFile(path, os.O_RDWR, 0666) if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return nil, errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrIsDir(err): return nil, errIsNotRegular @@ -182,7 +182,7 @@ func (fsi *fsIOPool) Create(path string) (wlk *lock.LockedFile, err error) { wlk, err = lock.LockedOpenFile(path, os.O_RDWR|os.O_CREATE, 0666) if err != nil { switch { - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrIsDir(err): return nil, errIsNotRegular diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 7bcc8413b..ce0ac6998 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -330,7 +330,7 @@ func (fs *FSObjects) crawlBucket(ctx context.Context, bucket string, cache dataU cache, err = crawlDataFolder(ctx, fs.fsPath, cache, func(item crawlItem) (int64, error) { bucket, object := item.bucket, item.objectPath() fsMetaBytes, err := ioutil.ReadFile(pathJoin(fs.fsPath, minioMetaBucket, bucketMetaPrefix, bucket, object, fs.metaJSONFile)) - if err != nil && !os.IsNotExist(err) { + if err != nil && !osIsNotExist(err) { return 0, errSkipFile } diff --git a/cmd/metacache-walk.go b/cmd/metacache-walk.go index fd4628aff..62c7ab99e 100644 --- a/cmd/metacache-walk.go +++ b/cmd/metacache-walk.go @@ -65,7 +65,7 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -190,7 +190,7 @@ func (s *xlStorage) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writ meta.name = strings.TrimSuffix(meta.name, globalDirSuffixWithSlash) + slashSeparator } out <- meta - case os.IsNotExist(err): + case osIsNotExist(err): meta.metadata, err = ioutil.ReadFile(pathJoin(volumeDir, meta.name, xlStorageFormatFileV1)) if err == nil { // Maybe rename? Would make it inconsistent across disks though. diff --git a/cmd/object-api-putobject_test.go b/cmd/object-api-putobject_test.go index f4718c706..ed9efa318 100644 --- a/cmd/object-api-putobject_test.go +++ b/cmd/object-api-putobject_test.go @@ -409,7 +409,7 @@ func testObjectAPIMultipartPutObjectStaleFiles(obj ObjectLayer, instanceType str files, err := ioutil.ReadDir(tmpMetaDir) if err != nil { // Its OK to have non-existen tmpMetaDir. - if os.IsNotExist(err) { + if osIsNotExist(err) { continue } diff --git a/cmd/os-readdir_unix.go b/cmd/os-readdir_unix.go index 1c3a461b1..aca99911e 100644 --- a/cmd/os-readdir_unix.go +++ b/cmd/os-readdir_unix.go @@ -181,7 +181,7 @@ func readDirN(dirPath string, count int) (entries []string, err error) { // It got deleted in the meantime, not found // or returns too many symlinks ignore this // file/directory. - if os.IsNotExist(err) || isSysErrPathNotFound(err) || + if osIsNotExist(err) || isSysErrPathNotFound(err) || isSysErrTooManySymlinks(err) { continue } diff --git a/cmd/os-reliable.go b/cmd/os-reliable.go index c76709d2e..0edecb5e2 100644 --- a/cmd/os-reliable.go +++ b/cmd/os-reliable.go @@ -103,7 +103,7 @@ func reliableMkdirAll(dirPath string, mode os.FileMode) (err error) { // Creates all the parent directories, with mode 0777 mkdir honors system umask. if err = os.MkdirAll(dirPath, mode); err != nil { // Retry only for the first retryable error. - if os.IsNotExist(err) && i == 0 { + if osIsNotExist(err) && i == 0 { i++ continue } @@ -131,8 +131,8 @@ func renameAll(srcFilePath, dstFilePath string) (err error) { if err = reliableRename(srcFilePath, dstFilePath); err != nil { switch { - case isSysErrNotDir(err) && !os.IsNotExist(err): - // Windows can have both isSysErrNotDir(err) and os.IsNotExist(err) returning + case isSysErrNotDir(err) && !osIsNotExist(err): + // Windows can have both isSysErrNotDir(err) and osIsNotExist(err) returning // true if the source file path contains an inexistant directory. In that case, // we want to return errFileNotFound instead, which will honored in subsequent // switch cases @@ -144,9 +144,9 @@ func renameAll(srcFilePath, dstFilePath string) (err error) { return errFileAccessDenied case isSysErrCrossDevice(err): return fmt.Errorf("%w (%s)->(%s)", errCrossDeviceLink, srcFilePath, dstFilePath) - case os.IsNotExist(err): + case osIsNotExist(err): return errFileNotFound - case os.IsExist(err): + case osIsExist(err): // This is returned only when destination is a directory and we // are attempting a rename from file to directory. return errIsNotRegular @@ -168,7 +168,7 @@ func reliableRename(srcFilePath, dstFilePath string) (err error) { // After a successful parent directory create attempt a renameAll. if err = os.Rename(srcFilePath, dstFilePath); err != nil { // Retry only for the first retryable error. - if os.IsNotExist(err) && i == 0 { + if osIsNotExist(err) && i == 0 { i++ continue } diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 01c3b7c13..5fd0cde4b 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -19,6 +19,7 @@ package cmd import ( "context" "crypto/tls" + "errors" "fmt" "net/http" "net/url" @@ -80,14 +81,11 @@ func formatErasureMigrateLocalEndpoints(endpoints Endpoints) error { index := index g.Go(func() error { epPath := endpoints[index].Path - formatPath := pathJoin(epPath, minioMetaBucket, formatConfigFile) - if _, err := os.Stat(formatPath); err != nil { - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("unable to access (%s) %w", formatPath, err) + err := formatErasureMigrate(epPath) + if err != nil && !errors.Is(err, os.ErrNotExist) { + return err } - return formatErasureMigrate(epPath) + return nil }, index) } for _, err := range g.Wait() { @@ -108,22 +106,6 @@ func formatErasureCleanupTmpLocalEndpoints(endpoints Endpoints) error { index := index g.Go(func() error { epPath := endpoints[index].Path - // If disk is not formatted there is nothing to be cleaned up. - formatPath := pathJoin(epPath, minioMetaBucket, formatConfigFile) - if _, err := os.Stat(formatPath); err != nil { - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("unable to access (%s) %w", formatPath, err) - } - if _, err := os.Stat(pathJoin(epPath, minioMetaTmpBucket+"-old")); err != nil { - if !os.IsNotExist(err) { - return fmt.Errorf("unable to access (%s) %w", - pathJoin(epPath, minioMetaTmpBucket+"-old"), - err) - } - } - // Need to move temporary objects left behind from previous run of minio // server to a unique directory under `minioMetaTmpBucket-old` to clean // up `minioMetaTmpBucket` for the current run. diff --git a/cmd/storage-errors.go b/cmd/storage-errors.go index b93aadf28..e15e10109 100644 --- a/cmd/storage-errors.go +++ b/cmd/storage-errors.go @@ -16,8 +16,6 @@ package cmd -import "os" - // errUnexpected - unexpected error, requires manual intervention. var errUnexpected = StorageErr("unexpected error, please report this issue at https://github.com/minio/minio/issues") @@ -127,10 +125,10 @@ func osErrToFileErr(err error) error { if err == nil { return nil } - if os.IsNotExist(err) { + if osIsNotExist(err) { return errFileNotFound } - if os.IsPermission(err) { + if osIsPermission(err) { return errFileAccessDenied } if isSysErrNotDir(err) { diff --git a/cmd/update.go b/cmd/update.go index 0dc849e1c..cb256df74 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -131,7 +131,7 @@ func GetCurrentReleaseTime() (releaseTime time.Time, err error) { func IsDocker() bool { if env.Get("MINIO_CI_CD", "") == "" { _, err := os.Stat("/.dockerenv") - if os.IsNotExist(err) { + if osIsNotExist(err) { return false } @@ -174,7 +174,7 @@ func IsKubernetes() bool { func IsBOSH() bool { // "/var/vcap/bosh" exists in BOSH deployed instance. _, err := os.Stat("/var/vcap/bosh") - if os.IsNotExist(err) { + if osIsNotExist(err) { return false } @@ -193,7 +193,7 @@ func getHelmVersion(helmInfoFilePath string) string { if err != nil { // Log errors and return "" as MinIO can be deployed // without Helm charts as well. - if !os.IsNotExist(err) { + if !osIsNotExist(err) { reqInfo := (&logger.ReqInfo{}).AppendTags("helmInfoFilePath", helmInfoFilePath) ctx := logger.SetReqInfo(GlobalContext, reqInfo) logger.LogIf(ctx, err) diff --git a/cmd/xl-storage-errors.go b/cmd/xl-storage-errors.go index 9c2a612ad..78673f76d 100644 --- a/cmd/xl-storage-errors.go +++ b/cmd/xl-storage-errors.go @@ -136,3 +136,15 @@ func isSysErrCrossDevice(err error) bool { func isSysErrTooManyFiles(err error) bool { return errors.Is(err, syscall.ENFILE) || errors.Is(err, syscall.EMFILE) } + +func osIsNotExist(err error) bool { + return errors.Is(err, os.ErrNotExist) +} + +func osIsPermission(err error) bool { + return errors.Is(err, os.ErrPermission) +} + +func osIsExist(err error) bool { + return errors.Is(err, os.ErrExist) +} diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index d5fbe01ec..8e3dd4c4c 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -166,10 +166,10 @@ func getValidPath(path string, requireDirectIO bool) (string, error) { } fi, err := os.Stat(path) - if err != nil && !os.IsNotExist(err) { + if err != nil && !osIsNotExist(err) { return path, err } - if os.IsNotExist(err) { + if osIsNotExist(err) { // Disk not found create it. if err = os.MkdirAll(path, 0777); err != nil { return path, err @@ -282,7 +282,7 @@ func getDiskInfo(diskPath string) (di disk.Info, err error) { } switch { - case os.IsNotExist(err): + case osIsNotExist(err): err = errDiskNotFound case isSysErrTooLong(err): err = errFileNameTooLong @@ -521,20 +521,20 @@ func (s *xlStorage) GetDiskID() (string, error) { fi, err := os.Stat(formatFile) if err != nil { // If the disk is still not initialized. - if os.IsNotExist(err) { + if osIsNotExist(err) { _, err = os.Stat(s.diskPath) if err == nil { // Disk is present but missing `format.json` return "", errUnformattedDisk } - if os.IsNotExist(err) { + if osIsNotExist(err) { return "", errDiskNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return "", errDiskAccessDenied } logger.LogIf(GlobalContext, err) // log unexpected errors return "", errCorruptedFormat - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return "", errDiskAccessDenied } logger.LogIf(GlobalContext, err) // log unexpected errors @@ -550,20 +550,20 @@ func (s *xlStorage) GetDiskID() (string, error) { b, err := ioutil.ReadFile(formatFile) if err != nil { // If the disk is still not initialized. - if os.IsNotExist(err) { + if osIsNotExist(err) { _, err = os.Stat(s.diskPath) if err == nil { // Disk is present but missing `format.json` return "", errUnformattedDisk } - if os.IsNotExist(err) { + if osIsNotExist(err) { return "", errDiskNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return "", errDiskAccessDenied } logger.LogIf(GlobalContext, err) // log unexpected errors return "", errCorruptedFormat - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return "", errDiskAccessDenied } logger.LogIf(GlobalContext, err) // log unexpected errors @@ -592,7 +592,7 @@ func (s *xlStorage) SetDiskID(id string) { func (s *xlStorage) MakeVolBulk(ctx context.Context, volumes ...string) (err error) { for _, volume := range volumes { if err = s.MakeVol(ctx, volume); err != nil { - if os.IsPermission(err) { + if osIsPermission(err) { return errVolumeAccessDenied } } @@ -618,11 +618,11 @@ func (s *xlStorage) MakeVol(ctx context.Context, volume string) (err error) { if _, err := os.Stat(volumeDir); err != nil { // Volume does not exist we proceed to create. - if os.IsNotExist(err) { + if osIsNotExist(err) { // Make a volume entry, with mode 0777 mkdir honors system umask. err = os.MkdirAll(volumeDir, 0777) } - if os.IsPermission(err) { + if osIsPermission(err) { return errDiskAccessDenied } else if isSysErrIO(err) { return errFaultyDisk @@ -663,7 +663,7 @@ func listVols(dirPath string) ([]VolInfo, error) { fi, err = os.Stat(pathJoin(dirPath, entry)) if err != nil { // If the file does not exist, skip the entry. - if os.IsNotExist(err) { + if osIsNotExist(err) { continue } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -696,7 +696,7 @@ func (s *xlStorage) StatVol(ctx context.Context, volume string) (vol VolInfo, er var st os.FileInfo st, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return VolInfo{}, errVolumeNotFound } else if isSysErrIO(err) { return VolInfo{}, errFaultyDisk @@ -733,11 +733,11 @@ func (s *xlStorage) DeleteVol(ctx context.Context, volume string, forceDelete bo if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return errVolumeNotFound case isSysErrNotEmpty(err): return errVolumeNotEmpty - case os.IsPermission(err): + case osIsPermission(err): return errDiskAccessDenied case isSysErrIO(err): return errFaultyDisk @@ -770,7 +770,7 @@ func (s *xlStorage) ListDirSplunk(volume, dirPath string, count int) (entries [] } if _, err = os.Stat(volumeDir); err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -810,7 +810,7 @@ func (s *xlStorage) isLeaf(volume string, leafPath string) bool { if err == nil { return true } - if os.IsNotExist(err) { + if osIsNotExist(err) { // We need a fallback code where directory might contain // legacy `xl.json`, in such situation we just rename // and proceed if rename is successful we know that it @@ -846,7 +846,7 @@ func (s *xlStorage) WalkVersions(ctx context.Context, volume, dirPath, marker st // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -929,7 +929,7 @@ func (s *xlStorage) ListDir(ctx context.Context, volume, dirPath string, count i } if _, err = os.Stat(volumeDir); err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -1090,7 +1090,7 @@ func (s *xlStorage) renameLegacyMetadata(volume, path string) error { //gi Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -1127,9 +1127,9 @@ func (s *xlStorage) renameLegacyMetadata(volume, path string) error { return errFileNotFound case isSysErrCrossDevice(err): return fmt.Errorf("%w (%s)->(%s)", errCrossDeviceLink, srcFilePath, dstFilePath) - case os.IsNotExist(err): + case osIsNotExist(err): return errFileNotFound - case os.IsExist(err): + case osIsExist(err): // This is returned only when destination is a directory and we // are attempting a rename from file to directory. return errIsNotRegular @@ -1208,7 +1208,7 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -1227,9 +1227,9 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu // Open the file for reading. buf, err = ioutil.ReadFile(filePath) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errFileNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return nil, errFileAccessDenied } else if errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.EISDIR) { return nil, errFileNotFound @@ -1277,7 +1277,7 @@ func (s *xlStorage) ReadFile(ctx context.Context, volume string, path string, of // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return 0, errVolumeNotFound } else if isSysErrIO(err) { return 0, errFaultyDisk @@ -1295,9 +1295,9 @@ func (s *xlStorage) ReadFile(ctx context.Context, volume string, path string, of file, err := os.Open(filePath) if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return 0, errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return 0, errFileAccessDenied case isSysErrNotDir(err): return 0, errFileAccessDenied @@ -1364,7 +1364,7 @@ func (s *xlStorage) openFile(volume, path string, mode int) (f *os.File, err err // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -1397,7 +1397,7 @@ func (s *xlStorage) openFile(volume, path string, mode int) (f *os.File, err err switch { case isSysErrNotDir(err): return nil, errFileAccessDenied - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrIO(err): return nil, errFaultyDisk @@ -1474,7 +1474,7 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -1492,9 +1492,9 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off file, err := disk.OpenFileDirectIO(filePath, os.O_RDONLY, 0666) if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return nil, errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrNotDir(err): return nil, errFileAccessDenied @@ -1515,9 +1515,9 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off file, err := os.Open(filePath) if err != nil { switch { - case os.IsNotExist(err): + case osIsNotExist(err): return nil, errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return nil, errFileAccessDenied case isSysErrNotDir(err): return nil, errFileAccessDenied @@ -1595,7 +1595,7 @@ func (s *xlStorage) CreateFile(ctx context.Context, volume, path string, fileSiz // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -1612,9 +1612,9 @@ func (s *xlStorage) CreateFile(ctx context.Context, volume, path string, fileSiz // with mode 0777 mkdir honors system umask. if err = mkdirAll(slashpath.Dir(filePath), 0777); err != nil { switch { - case os.IsPermission(err): + case osIsPermission(err): return errFileAccessDenied - case os.IsExist(err): + case osIsExist(err): return errFileAccessDenied case isSysErrIO(err): return errFaultyDisk @@ -1629,9 +1629,9 @@ func (s *xlStorage) CreateFile(ctx context.Context, volume, path string, fileSiz w, err := disk.OpenFileDirectIO(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666) if err != nil { switch { - case os.IsPermission(err): + case osIsPermission(err): return errFileAccessDenied - case os.IsExist(err): + case osIsExist(err): return errFileAccessDenied case isSysErrIO(err): return errFaultyDisk @@ -1746,7 +1746,7 @@ func (s *xlStorage) CheckParts(ctx context.Context, volume string, path string, // Stat a volume entry. if _, err = os.Stat(volumeDir); err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } return err @@ -1792,7 +1792,7 @@ func (s *xlStorage) CheckFile(ctx context.Context, volume string, path string) e // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } return err @@ -1809,7 +1809,7 @@ func (s *xlStorage) CheckFile(ctx context.Context, volume string, path string) e } st, err := os.Stat(filePath) - if err != nil && !os.IsNotExist(err) { + if err != nil && !osIsNotExist(err) { return osErrToFileErr(err) } if st == nil { @@ -1861,9 +1861,9 @@ func deleteFile(basePath, deletePath string, recursive bool) error { // this functionality, and sometimes uses recursion that should not // error on parent directories. return nil - case os.IsNotExist(err): + case osIsNotExist(err): return errFileNotFound - case os.IsPermission(err): + case osIsPermission(err): return errFileAccessDenied case isSysErrIO(err): return errFaultyDisk @@ -1896,9 +1896,9 @@ func (s *xlStorage) Delete(ctx context.Context, volume string, path string, recu // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return errVolumeAccessDenied } else if isSysErrIO(err) { return errFaultyDisk @@ -1931,9 +1931,9 @@ func (s *xlStorage) DeleteFileBulk(volume string, paths []string) (errs []error, // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return nil, errVolumeNotFound - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return nil, errVolumeAccessDenied } else if isSysErrIO(err) { return nil, errFaultyDisk @@ -1976,7 +1976,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, // Stat a volume entry. _, err = os.Stat(srcVolumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -1985,7 +1985,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, } _, err = os.Stat(dstVolumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -2026,7 +2026,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, dstBuf, err := ioutil.ReadFile(dstFilePath) if err != nil { - if !os.IsNotExist(err) { + if !osIsNotExist(err) { return osErrToFileErr(err) } err = s.renameLegacyMetadata(dstVolume, dstPath) @@ -2035,7 +2035,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, } if err == nil { dstBuf, err = ioutil.ReadFile(dstFilePath) - if err != nil && !os.IsNotExist(err) { + if err != nil && !osIsNotExist(err) { return osErrToFileErr(err) } } @@ -2189,7 +2189,7 @@ func (s *xlStorage) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolum // Stat a volume entry. _, err = os.Stat(srcVolumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -2198,7 +2198,7 @@ func (s *xlStorage) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolum } _, err = os.Stat(dstVolumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk @@ -2231,7 +2231,7 @@ func (s *xlStorage) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolum if err == nil && !isDirEmpty(dstFilePath) { return errFileAccessDenied } - if err != nil && !os.IsNotExist(err) { + if err != nil && !osIsNotExist(err) { return err } // Empty destination remove it before rename. @@ -2342,11 +2342,11 @@ func (s *xlStorage) VerifyFile(ctx context.Context, volume, path string, fi File // Stat a volume entry. _, err = os.Stat(volumeDir) if err != nil { - if os.IsNotExist(err) { + if osIsNotExist(err) { return errVolumeNotFound } else if isSysErrIO(err) { return errFaultyDisk - } else if os.IsPermission(err) { + } else if osIsPermission(err) { return errVolumeAccessDenied } return err