diff --git a/dnf5-plugins/copr_plugin/copr_config.cpp b/dnf5-plugins/copr_plugin/copr_config.cpp
index 8714f2813..483207f05 100644
--- a/dnf5-plugins/copr_plugin/copr_config.cpp
+++ b/dnf5-plugins/copr_plugin/copr_config.cpp
@@ -22,6 +22,8 @@ along with libdnf. If not, see .
#include "copr_constants.hpp"
+#include "libdnf5/utils/os_release.hpp"
+
#include
@@ -42,6 +44,8 @@ void CoprConfig::load_all_configuration() {
// https://github.com/rpm-software-management/dnf5/issues/513
etc_dir = "/etc";
+ libdnf5::utils::OSRelease os_release(etc_dir / "os-release");
+
load_copr_config_file("/usr/share/dnf/plugins/copr.vendor.conf");
load_copr_config_file(etc_dir / "dnf/plugins/copr.vendor.conf");
load_copr_config_file(etc_dir / "dnf/plugins/copr.conf");
diff --git a/dnf5-plugins/copr_plugin/copr_config.hpp b/dnf5-plugins/copr_plugin/copr_config.hpp
index 974d3194f..0fb5c27f1 100644
--- a/dnf5-plugins/copr_plugin/copr_config.hpp
+++ b/dnf5-plugins/copr_plugin/copr_config.hpp
@@ -20,8 +20,6 @@ along with libdnf. If not, see .
#ifndef DNF5_COMMANDS_COPR_COPR_CONFIG_HPP
#define DNF5_COMMANDS_COPR_COPR_CONFIG_HPP
-#include "os_release.hpp"
-
#include
#include
#include
@@ -31,7 +29,6 @@ namespace dnf5 {
class CoprConfig : public libdnf5::ConfigParser {
private:
libdnf5::Base & base;
- OSRelease os_release;
void load_copr_config_file(const std::string & filename);
void load_all_configuration();
diff --git a/dnf5-plugins/copr_plugin/os_release.cpp b/dnf5-plugins/copr_plugin/os_release.cpp
deleted file mode 100644
index ca74604b4..000000000
--- a/dnf5-plugins/copr_plugin/os_release.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "os_release.hpp"
-
-#include
-#include
-#include
-#include
-
-
-OSRelease::OSRelease() {}
-
-std::string OSRelease::get_value(const std::string & key, const std::string & default_value) {
- initialize();
- if (map.find(key) == map.end())
- return default_value;
- return map[key];
-}
-
-
-void OSRelease::initialize() {
- if (initialized_)
- return;
-
- initialized_ = true;
- std::filesystem::path filename;
- if (const char * pathname = std::getenv("TEST_COPR_CONFIG_DIR"))
- filename = pathname;
- else
- filename = "/etc";
- filename /= "os-release";
- std::ifstream infile(filename);
- if (!std::filesystem::exists(filename))
- return;
-
- const std::regex r_no_quotes("^([A-Z_]+)=(\\w+)");
- const std::regex r_quotes("^([A-Z_]+)=\"([\\w\\s]+)\"");
- std::smatch match;
- std::string line;
-
- while (std::getline(infile, line)) {
- if (std::regex_match(line, match, r_no_quotes)) {
- map[match[1]] = match[2];
- continue;
- }
- if (std::regex_match(line, match, r_quotes)) {
- map[match[1]] = match[2];
- continue;
- }
- }
-}
-
-
-bool OSRelease::initialized_ = false;
-std::map OSRelease::map = {};
diff --git a/include/libdnf5/utils/os_release.hpp b/include/libdnf5/utils/os_release.hpp
new file mode 100644
index 000000000..205375aba
--- /dev/null
+++ b/include/libdnf5/utils/os_release.hpp
@@ -0,0 +1,61 @@
+/*
+Copyright Contributors to the libdnf project.
+
+This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
+
+Libdnf is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 2.1 of the License, or
+(at your option) any later version.
+
+Libdnf is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with libdnf. If not, see .
+*/
+
+#ifndef LIBDNF5_UTILS_OS_RELEASE_HPP
+#define LIBDNF5_UTILS_OS_RELEASE_HPP
+
+#include "libdnf5/defs.h"
+
+#include
+#include