Enforce that --confdir must be a directory (#2051)

* Enforce that when we are using --confdir - the path that is passed in has to be a directory and not a file
This commit is contained in:
abraunegg 2022-07-20 10:09:20 +10:00 committed by GitHub
parent a17a667e44
commit 031c82922d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -221,6 +221,20 @@ final class Config
mkdirRecurse(configDirName);
// Configure the applicable permissions for the folder
configDirName.setAttributes(returnRequiredDirectoryPermisions());
} else {
// The config path exists
// The path that exists must be a directory, not a file
if (!isDir(configDirName)) {
if (!confdirOption.empty) {
// the configuration path was passed in by the user .. user error
writeln("ERROR: --confdir entered value is an existing file instead of an existing directory");
} else {
// other error
writeln("ERROR: ~/.config/onedrive is a file rather than a directory");
}
// Must exit
exit(EXIT_FAILURE);
}
}
// configDirName has a trailing /

View file

@ -146,6 +146,9 @@ int main(string[] args)
return EXIT_FAILURE;
}
// confdirOption must be a directory, not a file
// - By default ~/.config/onedrive will be used
// - If the user is using --confdir , the confdirOption needs to be evaluated when trying to load any file
// load configuration file if available
auto cfg = new config.Config(confdirOption);
if (!cfg.initialize()) {