1
mirror of https://github.com/rclone/rclone synced 2025-01-10 13:06:26 +01:00

config: treat any config file paths with filename notfound as memory-only config (#5235)

This commit is contained in:
albertony 2021-04-18 00:09:03 +02:00 committed by GitHub
parent b456be4303
commit 3544e09e95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 20 deletions

View File

@ -686,8 +686,8 @@ to run in "portable" mode by downloading rclone executable to a
writable directory and then create an empty file `rclone.conf` in the
same directory.
If the location is set to empty string `""` or the special value
`/notfound`, or the os null device represented by value `NUL` on
If the location is set to empty string `""` or path to a file
with name `notfound`, or the os null device represented by value `NUL` on
Windows and `/dev/null` on Unix systems, then rclone will keep the
config file in memory only.
@ -1920,11 +1920,12 @@ Nevertheless, rclone will read any configuration file found
according to the rules described [above](https://rclone.org/docs/#config-config-file).
If an encrypted configuration file is found, this means you will be prompted for
password (unless using `--password-command`). To avoid this, you can bypass
the loading of the configuration file by overriding the location with an empty
string `""` or the special value `/notfound`, or the os null device represented
by value `NUL` on Windows and `/dev/null` on Unix systems (before rclone
version 1.55 only this null device alternative was supported).
E.g. `rclone --config="" genautocomplete bash`.
the loading of the default configuration file by overriding the location,
e.g. with one of the documented special values for memory-only configuration:
```
rclone genautocomplete bash --config=""
```
Developer options
-----------------

View File

@ -29,7 +29,7 @@ import (
const (
configFileName = "rclone.conf"
hiddenConfigFileName = "." + configFileName
noConfigFile = "/notfound"
noConfigFile = "notfound"
// ConfigToken is the key used to store the token under
ConfigToken = "token"
@ -113,16 +113,12 @@ var (
Password = random.Password
)
var (
configPath string
noConfigPath string
)
var configPath string
func init() {
// Set the function pointers up in fs
fs.ConfigFileGet = FileGetFlag
fs.ConfigFileSet = SetValueAndSave
noConfigPath, _ = filepath.Abs(noConfigFile)
configPath = makeConfigPath()
}
@ -320,15 +316,12 @@ func SetConfigPath(path string) (err error) {
var cfgPath string
if path == "" || path == os.DevNull {
cfgPath = ""
} else if filepath.Base(path) == noConfigFile {
cfgPath = ""
} else if err = file.IsReserved(path); err != nil {
return err
} else {
if cfgPath, err = filepath.Abs(path); err != nil {
return err
}
if cfgPath == noConfigPath {
cfgPath = ""
}
} else if cfgPath, err = filepath.Abs(path); err != nil {
return err
}
configPath = cfgPath
return nil