Skip to content

Commit

Permalink
const: Shared constant defining RPM transaction lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-kolarik committed May 21, 2024
1 parent a597c83 commit 576363c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5-cli/utils/userconfirm.hpp>
#include <libdnf5/base/base.hpp>
#include <libdnf5/common/xdg.hpp>
#include <libdnf5/conf/const.hpp>
#include <libdnf5/logger/factory.hpp>
#include <libdnf5/logger/global_logger.hpp>
#include <libdnf5/logger/memory_buffer_logger.hpp>
Expand Down Expand Up @@ -1125,7 +1126,7 @@ static bool cmd_requires_privileges(dnf5::Context & context) {

static bool user_has_privileges(dnf5::Context & context) {
std::filesystem::path lock_file_path = context.get_base().get_config().get_installroot_option().get_value();
lock_file_path /= "run/dnf/rpm.transaction.lock";
lock_file_path /= std::filesystem::path(libdnf5::TRANSACTION_LOCK_FILEPATH).relative_path();
libdnf5::utils::Locker locker(lock_file_path);
try {
return locker.write_lock();
Expand Down
2 changes: 2 additions & 0 deletions include/libdnf5/conf/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const std::vector<std::string> REPOSITORY_CONF_DIRS{
"/etc/yum.repos.d", "/etc/distro.repos.d", "/usr/share/dnf5/repos.d"};
constexpr const char * REPOS_OVERRIDE_DIR = "/etc/dnf/repos.override.d";

constexpr const char * TRANSACTION_LOCK_FILEPATH = "/run/dnf/rpmtransaction.lock";

// More important varsdirs must be on the end of vector
const std::vector<std::string> VARS_DIRS{"/usr/share/dnf5/vars.d", "/etc/dnf/vars"};

Expand Down
3 changes: 2 additions & 1 deletion libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/common/sack/exclude_flags.hpp"
#include "libdnf5/common/sack/query_cmp.hpp"
#include "libdnf5/comps/group/query.hpp"
#include "libdnf5/conf/const.hpp"
#include "libdnf5/repo/package_downloader.hpp"
#include "libdnf5/rpm/package_query.hpp"
#include "libdnf5/utils/bgettext/bgettext-lib.h"
Expand Down Expand Up @@ -853,7 +854,7 @@ Transaction::TransactionRunResult Transaction::Impl::_run(

// acquire the lock
std::filesystem::path lock_file_path = config.get_installroot_option().get_value();
lock_file_path /= "run/dnf/rpmtransaction.lock";
lock_file_path /= std::filesystem::path(libdnf5::TRANSACTION_LOCK_FILEPATH).relative_path();
std::filesystem::create_directories(lock_file_path.parent_path());

libdnf5::utils::Locker locker(lock_file_path);
Expand Down

0 comments on commit 576363c

Please sign in to comment.