Revert "init: Honor config-dir flag when it is passed as global or local flag (#3337)"

This reverts commit e2ef95af7d.

This is reverted since the previous patch caused crashes.
This commit is contained in:
Harshavardhana 2016-11-23 17:27:42 -08:00
parent 12c1abed98
commit dd74e5a809
5 changed files with 68 additions and 89 deletions

View File

@ -53,12 +53,11 @@ const (
)
var (
globalQuiet = false // quiet flag set via command line.
globalConfigDir = mustGetConfigPath() // config-dir flag set via command line
// Add new global flags here.
globalQuiet = false // Quiet flag set via command line.
globalIsDistXL = false // "Is Distributed?" flag.
// Add new global flags here.
// Maximum cache size.
globalMaxCacheSize = uint64(maxCacheSize)
// Cache expiry.

View File

@ -148,42 +148,19 @@ func checkMainSyntax(c *cli.Context) {
}
}
// Parse command arguments and set global variables accordingly
func setGlobalsFromContext(c *cli.Context) {
// Set config dir
switch {
case c.IsSet("config-dir"):
globalConfigDir = c.String("config-dir")
case c.GlobalIsSet("config-dir"):
globalConfigDir = c.GlobalString("config-dir")
}
if globalConfigDir == "" {
// Main main for minio server.
func Main() {
app := registerApp()
app.Before = func(c *cli.Context) error {
configDir := c.GlobalString("config-dir")
if configDir == "" {
fatalIf(errors.New("Config directory is empty"), "Unable to get config file.")
}
// Set global quiet flag.
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
}
// Check for updates and print a notification message
func checkUpdate() {
// Do not print update messages, if quiet flag is set.
if !globalQuiet {
updateMsg, _, err := getReleaseUpdate(minioUpdateStableURL, 1*time.Second)
if err != nil {
// Ignore any errors during getReleaseUpdate(), possibly
// because of network errors.
return
}
if updateMsg.Update {
console.Println(updateMsg)
}
}
}
// Generic Minio initialization to create/load config, prepare loggers, etc..
func minioInit() {
// Sets new config directory.
setGlobalConfigPath(globalConfigDir)
setGlobalConfigPath(configDir)
// Valid input arguments to main.
checkMainSyntax(c)
// Migrate any old version of config / state files to newer format.
migrate()
@ -217,15 +194,24 @@ func minioInit() {
// Init the error tracing module.
initError()
}
// Main main for minio server.
func Main() {
app := registerApp()
app.Before = func(c *cli.Context) error {
// Valid input arguments to main.
checkMainSyntax(c)
// Set global quiet flag.
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
// Do not print update messages, if quiet flag is set.
if !globalQuiet {
if c.Args().Get(0) != "update" {
updateMsg, _, err := getReleaseUpdate(minioUpdateStableURL, 1*time.Second)
if err != nil {
// Ignore any errors during getReleaseUpdate(), possibly
// because of network errors.
return nil
}
if updateMsg.Update {
console.Println(updateMsg)
}
}
}
return nil
}

View File

@ -363,13 +363,8 @@ func serverMain(c *cli.Context) {
cli.ShowCommandHelpAndExit(c, "server", 1)
}
// Set global variables after parsing passed arguments
setGlobalsFromContext(c)
checkUpdate()
// Generic initialization
minioInit()
// Set global quiet flag.
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
// Server address.
serverAddr := c.String("address")

View File

@ -265,9 +265,8 @@ func getReleaseUpdate(updateURL string, duration time.Duration) (updateMsg updat
// main entry point for update command.
func mainUpdate(ctx *cli.Context) {
setGlobalsFromContext(ctx)
if globalQuiet {
// Set global quiet flag.
if ctx.Bool("quiet") || ctx.GlobalBool("quiet") {
return
}

View File

@ -43,10 +43,10 @@ func mainVersion(ctx *cli.Context) {
if len(ctx.Args()) != 0 {
cli.ShowCommandHelpAndExit(ctx, "version", 1)
}
setGlobalsFromContext(ctx)
checkUpdate()
// Set global quiet flag.
if ctx.Bool("quiet") || ctx.GlobalBool("quiet") {
return
}
console.Println("Version: " + Version)
console.Println("Release-Tag: " + ReleaseTag)