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