mirror of
https://github.com/rclone/rclone.git
synced 2025-02-20 07:48:33 +02:00
remove duplicate code
This commit is contained in:
parent
30ac9d920a
commit
2793d4b4cc
@ -225,23 +225,23 @@ var errorConfigFileNotFound = errors.New("config file not found")
|
|||||||
// loadConfigFile will load a config file, and
|
// loadConfigFile will load a config file, and
|
||||||
// automatically decrypt it.
|
// automatically decrypt it.
|
||||||
func loadConfigFile() (*goconfig.ConfigFile, error) {
|
func loadConfigFile() (*goconfig.ConfigFile, error) {
|
||||||
b, err := ioutil.ReadFile(ConfigPath)
|
|
||||||
envpw := os.Getenv("RCLONE_CONFIG_PASS")
|
envpw := os.Getenv("RCLONE_CONFIG_PASS")
|
||||||
|
if len(configKey) == 0 && envpw != "" {
|
||||||
|
err := setConfigPassword(envpw)
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf(nil, "Using RCLONE_CONFIG_PASS returned: %v", err)
|
||||||
|
} else {
|
||||||
|
fs.Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := ioutil.ReadFile(ConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if len(configKey) == 0 && envpw != "" {
|
|
||||||
err := setConfigPassword(envpw)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Using RCLONE_CONFIG_PASS returned:", err)
|
|
||||||
} else {
|
|
||||||
fs.Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, errorConfigFileNotFound
|
return nil, errorConfigFileNotFound
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find first non-empty line
|
// Find first non-empty line
|
||||||
r := bufio.NewReader(bytes.NewBuffer(b))
|
r := bufio.NewReader(bytes.NewBuffer(b))
|
||||||
for {
|
for {
|
||||||
@ -295,14 +295,6 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
|
|||||||
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
|
configKey = []byte(obscure.MustReveal(string(obscuredKey)))
|
||||||
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
|
fs.Debugf(nil, "using _RCLONE_CONFIG_KEY_FILE for configKey")
|
||||||
} else {
|
} else {
|
||||||
if len(configKey) == 0 && envpw != "" {
|
|
||||||
err := setConfigPassword(envpw)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Using RCLONE_CONFIG_PASS returned:", err)
|
|
||||||
} else {
|
|
||||||
fs.Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(configKey) == 0 {
|
if len(configKey) == 0 {
|
||||||
if !fs.Config.AskPassword {
|
if !fs.Config.AskPassword {
|
||||||
return nil, errors.New("unable to decrypt configuration and not allowed to ask for password - set RCLONE_CONFIG_PASS to your configuration password")
|
return nil, errors.New("unable to decrypt configuration and not allowed to ask for password - set RCLONE_CONFIG_PASS to your configuration password")
|
||||||
@ -327,7 +319,6 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
|
|||||||
// Retry
|
// Retry
|
||||||
fs.Errorf(nil, "Couldn't decrypt configuration, most likely wrong password.")
|
fs.Errorf(nil, "Couldn't decrypt configuration, most likely wrong password.")
|
||||||
configKey = nil
|
configKey = nil
|
||||||
envpw = ""
|
|
||||||
}
|
}
|
||||||
return goconfig.LoadFromReader(bytes.NewBuffer(out))
|
return goconfig.LoadFromReader(bytes.NewBuffer(out))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user