From b9c113af754540341d9529532fbadb7525168102 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Fri, 4 Feb 2022 22:53:04 +0200 Subject: [PATCH] util: Avoid buggy std::filesystem:::create_directories() call Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04) std::filesystem:::create_directories() call fails to handle symbol links properly. --- src/util/system.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index 0ee63f6381d..d51ba07d941 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -443,14 +443,18 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const } else { path = GetDefaultDataDir(); } - if (net_specific) - path /= fs::PathFromString(BaseParams().DataDir()); - if (fs::create_directories(path)) { - // This is the first run, create wallets subdirectory too + if (!fs::exists(path)) { fs::create_directories(path / "wallets"); } + if (net_specific && !BaseParams().DataDir().empty()) { + path /= fs::PathFromString(BaseParams().DataDir()); + if (!fs::exists(path)) { + fs::create_directories(path / "wallets"); + } + } + path = StripRedundantLastElementsOfPath(path); return path; }