From 031c82922d190ed1a33700805c54ddebc326ed3a Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 20 Jul 2022 10:09:20 +1000 Subject: [PATCH] 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 --- src/config.d | 14 ++++++++++++++ src/main.d | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/config.d b/src/config.d index 761879ea..b9eeb982 100644 --- a/src/config.d +++ b/src/config.d @@ -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 / diff --git a/src/main.d b/src/main.d index 02ab78f2..f766c888 100644 --- a/src/main.d +++ b/src/main.d @@ -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()) {