diff --git a/src/control/XournalMain.cpp b/src/control/XournalMain.cpp index a11b18f6..5049a0c6 100644 --- a/src/control/XournalMain.cpp +++ b/src/control/XournalMain.cpp @@ -76,28 +76,28 @@ XournalMain::MigrateResult XournalMain::migrateSettings() { fs::path newConfigPath = Util::getConfigFolder(); if (!fs::exists(newConfigPath)) { - fs::path oldConfigPath(g_get_home_dir()); - oldConfigPath /= ".xournalpp"; - - if (!fs::exists(oldConfigPath)) { - g_message("Migrating configuration from %s to %s", oldConfigPath.string().c_str(), - newConfigPath.string().c_str()); - auto xdgConfDir = newConfigPath.parent_path(); + std::array oldPaths = { + fs::u8path(g_get_home_dir()) /= ".xournalpp", + }; + for (auto const& oldPath: oldPaths) { + if (!fs::is_directory(oldPath)) { + continue; + } + g_message("Migrating configuration from %s to %s", oldPath.c_str(), newConfigPath.c_str()); + Util::ensureFolderExists(newConfigPath.parent_path()); try { - if (!fs::exists(xdgConfDir)) { - fs::create_directories(xdgConfDir); - } - fs::copy(oldConfigPath, newConfigPath, fs::copy_options::recursive); - const char* msg = "Due to a recent update, Xournal++ has changed where its configuration files are " - "stored.\nThey have been automatically copied from\n\t{1}\nto\n\t{2}"; + fs::copy(oldPath, newConfigPath, fs::copy_options::recursive); + constexpr auto msg = "Due to a recent update, Xournal++ has changed where it's configuration files are " + "stored.\nThey have been automatically copied from\n\t{1}\nto\n\t{2}"; return {MigrateStatus::Success, - FS(_F(msg) % oldConfigPath.string().c_str() % newConfigPath.string().c_str())}; + FS(_F(msg) % oldPath.u8string().c_str() % newConfigPath.u8string().c_str())}; } catch (fs::filesystem_error const& except) { - const char* msg = "Due to a recent update, Xournal++ has changed where its configuration files are " - "stored.\nHowever, when attempting to copy\n\t{1}\nto\n\t{2}\nmigration failed:\n{3}"; + constexpr auto msg = + "Due to a recent update, Xournal++ has changed where it's configuration files are " + "stored.\nHowever, when attempting to copy\n\t{1}\nto\n\t{2}\nmigration failed:\n{3}"; g_message("Migration failed: %s", except.what()); return {MigrateStatus::Failure, - FS(_F(msg) % oldConfigPath.string().c_str() % newConfigPath.string().c_str() % except.what())}; + FS(_F(msg) % oldPath.u8string().c_str() % newConfigPath.u8string().c_str() % except.what())}; } } } diff --git a/src/util/PathUtil.cpp b/src/util/PathUtil.cpp index 2625cf6a..285cb05d 100644 --- a/src/util/PathUtil.cpp +++ b/src/util/PathUtil.cpp @@ -197,10 +197,12 @@ auto Util::getTmpDirSubfolder(const fs::path& subfolder) -> fs::path { } auto Util::ensureFolderExists(const fs::path& p) -> fs::path { - if (!fs::exists(p) && !fs::create_directories(p)) { + try { + fs::create_directories(p); + } catch (fs::filesystem_error const& fe) { Util::execInUiThread([=]() { - string msg = FS(_F("Could not create folder: {1}") % p.string()); - g_warning("%s", msg.c_str()); + string msg = FS(_F("Could not create folder: {1}\nFailed with error: {2}") % p.string() % fe.what()); + g_warning("%s %s", msg.c_str(), fe.what()); XojMsgBox::showErrorToUser(nullptr, msg); }); }