diff --git a/dnf5-plugins/copr_plugin/json.cpp b/dnf5-plugins/copr_plugin/json.cpp index 1f7fd7908..2b0efd2a3 100644 --- a/dnf5-plugins/copr_plugin/json.cpp +++ b/dnf5-plugins/copr_plugin/json.cpp @@ -20,15 +20,16 @@ along with libdnf. If not, see . #include "json.hpp" #include "download_file.hpp" -#include "tempfile.hpp" + +#include "libdnf5/utils/fs/temp.hpp" #include #include Json::Json(libdnf5::Base & base, const std::string & url) { - auto temp_file = TempFile(); - download_file(base, url, temp_file.path); - std::ifstream file(temp_file.path); + auto temp_file = libdnf5::utils::fs::TempFile("/tmp", "dnf5-copr-plugin"); + download_file(base, url, temp_file.get_path()); + std::ifstream file(temp_file.get_path()); std::stringstream buffer; buffer << file.rdbuf(); root = json_tokener_parse(buffer.str().c_str()); diff --git a/dnf5-plugins/copr_plugin/tempfile.hpp b/dnf5-plugins/copr_plugin/tempfile.hpp deleted file mode 100644 index 6ea83f2c4..000000000 --- a/dnf5-plugins/copr_plugin/tempfile.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -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 DNF5_COMMANDS_COPR_TEMPFILE_HPP -#define DNF5_COMMANDS_COPR_TEMPFILE_HPP - -#include - -#include - -/// TODO: make copr plugin work with libdnf5::utils::fs::TempFile (not a libdnf5 API ATM) -class TempFile { -public: - std::filesystem::path path; - TempFile() { - char temp_template[] = "/tmp/dnf5-copr-plugin-XXXXXX"; - close(mkstemp(temp_template)); - path = temp_template; - } - ~TempFile() { unlink(path.c_str()); } -}; - -#endif // DNF5_COMMANDS_COPR_TEMPFILE_HPP