Canonicalize some user-provided paths

These paths get displayed to users, so showing the resolved path (e.g.,
without "../") is clearer. Also, these paths are created if they don't
exist. So if you provide something like
`-exportdir=doesntexist/../real_path`, Boost will create `doesntexist/`
if you create the directories before canonicalizing the path, even
though it isn't used.
This commit is contained in:
Greg Pfeil 2022-08-17 11:44:53 -06:00
parent e9b4a1af09
commit 8bf80ae641
1 changed files with 2 additions and 2 deletions

View File

@ -318,7 +318,7 @@ const fs::path GetExportDir()
fs::path path;
LOCK(cs_args);
if (mapArgs.count("-exportdir")) {
path = fs::system_complete(mapArgs["-exportdir"]);
path = fs::weakly_canonical(fs::system_complete(mapArgs["-exportdir"]));
if (fs::exists(path) && !fs::is_directory(path)) {
throw std::runtime_error(strprintf("The -exportdir '%s' already exists and is not a directory", path.string()));
}
@ -342,7 +342,7 @@ const fs::path &GetDataDir(bool fNetSpecific)
return path;
if (mapArgs.count("-datadir")) {
path = fs::system_complete(mapArgs["-datadir"]);
path = fs::weakly_canonical(fs::system_complete(mapArgs["-datadir"]));
if (!fs::is_directory(path)) {
path = "";
return path;