diff --git a/librepomgr/serversetup.cpp b/librepomgr/serversetup.cpp index fe274df..5469c7d 100644 --- a/librepomgr/serversetup.cpp +++ b/librepomgr/serversetup.cpp @@ -237,8 +237,16 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) } } // apply working directory + // note: As this function can run multiple times (as live-reconfigurations are supported) we + // must restore the initial working directory here so relative paths are always treated + // relative to the initial working directory. if (!workingDirectory.empty()) { try { + if (initialWorkingDirectory.empty()) { + initialWorkingDirectory = std::filesystem::current_path(); + } else { + std::filesystem::current_path(initialWorkingDirectory); + } workingDirectory = std::filesystem::absolute(workingDirectory); } catch (const std::filesystem::filesystem_error &e) { cerr << Phrases::WarningMessage << "Unable to determine absolute path of specified working directory: " << e.what() @@ -247,6 +255,11 @@ void ServiceSetup::loadConfigFiles(bool restoreStateAndDiscardDatabases) if (chdir(workingDirectory.c_str()) != 0) { cerr << Phrases::WarningMessage << "Unable to change the working directory to \"" << workingDirectory << "\": " << std::strerror(errno) << Phrases::EndFlush; + try { + workingDirectory = std::filesystem::current_path(); + } catch (const std::filesystem::filesystem_error &e) { + cerr << Phrases::WarningMessage << "Unable to determine effective working directory: " << e.what() << Phrases::EndFlush; + } } } // restore state/cache and discard databases diff --git a/librepomgr/serversetup.h b/librepomgr/serversetup.h index 51ac318..b6d2e36 100644 --- a/librepomgr/serversetup.h +++ b/librepomgr/serversetup.h @@ -40,6 +40,7 @@ struct LIBREPOMGR_EXPORT ServiceSetup : public LibPkg::Lockable { // -> acquire the setup lock for these std::string configFilePath = "server.conf"; std::string pacmanConfigFilePath = "/etc/pacman.conf"; + std::filesystem::path initialWorkingDirectory; std::string workingDirectory = "workingdir"; // variables relevant for the web server; only changed when (re)loading config