Rename config.json in config-dir with '.deprecated' extension (#6446)

Fixes #6444
master
Harshavardhana 6 years ago committed by Dee Koder
parent 5c0b98abf0
commit 12b4971b70
  1. 21
      cmd/config.go
  2. 6
      cmd/server-main.go

@ -23,6 +23,7 @@ import (
"errors"
"io"
"io/ioutil"
"os"
"path"
"runtime"
"time"
@ -227,6 +228,8 @@ func NewConfigSys() *ConfigSys {
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
func migrateConfigToMinioSys(objAPI ObjectLayer) error {
defer os.Rename(getConfigFile(), getConfigFile()+".deprecated")
// Verify if backend already has the file.
if err := checkServerConfig(context.Background(), objAPI); err != errConfigNotFound {
return err
@ -234,7 +237,13 @@ func migrateConfigToMinioSys(objAPI ObjectLayer) error {
var config = &serverConfig{}
if _, err := Load(getConfigFile(), config); err != nil {
return err
if !os.IsNotExist(err) {
return err
}
// Read from deprecate file as well if necessary.
if _, err = Load(getConfigFile()+".deprecated", config); err != nil {
return err
}
}
return saveServerConfig(context.Background(), objAPI, config)
@ -258,11 +267,11 @@ func initConfig(objAPI ObjectLayer) error {
if err := migrateConfig(); err != nil {
return err
}
// Migrates ${HOME}/.minio/config.json to '<export_path>/.minio.sys/config/config.json'
if err := migrateConfigToMinioSys(objAPI); err != nil {
return err
}
}
// Migrates ${HOME}/.minio/config.json or config.json.deprecated
// to '<export_path>/.minio.sys/config/config.json'
if err := migrateConfigToMinioSys(objAPI); err != nil {
return err
}
}

@ -265,6 +265,12 @@ func serverMain(ctx *cli.Context) {
globalActiveCred = config.Credential
}
if os.IsNotExist(err) {
if _, err = Load(getConfigFile()+".deprecated", config); err == nil {
globalActiveCred = config.Credential
}
}
if globalActiveCred.IsValid() {
// Credential is valid don't throw an error instead print a message regarding deprecation of 'config.json'
// based model and proceed to use it for now in distributed setup.

Loading…
Cancel
Save