summaryrefslogtreecommitdiff
path: root/backend/pkgtools.cpp
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-06-12 13:31:33 +0200
committerEugen Wissner <belka@caraus.de>2026-06-12 13:31:33 +0200
commit6719ed7ed31f293cbdb2d2cf1112489a96f783e0 (patch)
tree831dfc66751d722031217e96ff1899d306ff7e6d /backend/pkgtools.cpp
parentb90c277798de0630488cb983ca13b00b282525ff (diff)
parent1e12f2af8b9ec50144421d998e98e4809071e118 (diff)
downloadkatja-6719ed7ed31f293cbdb2d2cf1112489a96f783e0.tar.gz
Merge branch 'raii'
Diffstat (limited to 'backend/pkgtools.cpp')
-rw-r--r--backend/pkgtools.cpp44
1 files changed, 19 insertions, 25 deletions
diff --git a/backend/pkgtools.cpp b/backend/pkgtools.cpp
index 80dc4d8..6c387f3 100644
--- a/backend/pkgtools.cpp
+++ b/backend/pkgtools.cpp
@@ -81,7 +81,8 @@ public:
**/
bool download(JobData *job_data, const char *dest_dir_name, char *pkg_name) noexcept
{
- char *dest_filename, *source_url;
+ std::filesystem::path dest_filename;
+ std::string source_url;
bool ret = false;
sqlite3_stmt *statement = nullptr;
CURL *curl = nullptr;
@@ -100,22 +101,20 @@ public:
if (sqlite3_step(statement) == SQLITE_ROW)
{
- dest_filename = g_build_filename(dest_dir_name, sqlite3_column_text(statement, 1), nullptr);
- source_url = g_strconcat(this->mirror.c_str(),
- sqlite3_column_text(statement, 0),
- "/",
- sqlite3_column_text(statement, 1),
- nullptr);
+ dest_filename = std::filesystem::path(dest_dir_name)
+ / reinterpret_cast<const char *>(sqlite3_column_text(statement, 1));
+ source_url = this->mirror
+ + reinterpret_cast<const char *>(sqlite3_column_text(statement, 0))
+ + "/"
+ + reinterpret_cast<const char *>(sqlite3_column_text(statement, 1));
- ret = g_file_test(dest_filename, G_FILE_TEST_EXISTS)
- || get_file(&curl, source_url, dest_filename) == CURLE_OK;
+ ret = g_file_test(dest_filename.native().c_str(), G_FILE_TEST_EXISTS)
+ || get_file(&curl, source_url.c_str(), dest_filename.native().c_str()) == CURLE_OK;
if (curl)
{
curl_easy_cleanup(curl);
}
- g_free(source_url);
- g_free(dest_filename);
}
sqlite3_finalize(statement);
@@ -131,7 +130,7 @@ public:
**/
void install(JobData *job_data, char *pkg_name) noexcept
{
- char *pkg_filename, *cmd_line;
+ std::filesystem::path pkg_filename;
sqlite3_stmt *statement = nullptr;
if ((sqlite3_prepare_v2(job_data->db,
@@ -149,23 +148,18 @@ public:
if (sqlite3_step(statement) == SQLITE_ROW)
{
- pkg_filename = g_build_filename(LOCALSTATEDIR,
- "cache",
- "katja",
- "downloads",
- sqlite3_column_text(statement, 0),
- nullptr);
- cmd_line = g_strconcat("/sbin/upgradepkg --install-new ", pkg_filename, nullptr);
- g_spawn_command_line_sync(cmd_line, nullptr, nullptr, nullptr, nullptr);
- g_free(cmd_line);
-
- g_free(pkg_filename);
+ pkg_filename = std::filesystem::path(LOCALSTATEDIR)
+ / "cache" / "katja" / "downloads"
+ / reinterpret_cast<const char*>(sqlite3_column_text(statement, 0));
+
+ std::string cmd_line = "/sbin/upgradepkg --install-new " + pkg_filename.native();
+ g_spawn_command_line_sync(cmd_line.c_str(), nullptr, nullptr, nullptr, nullptr);
}
sqlite3_finalize(statement);
}
- virtual std::forward_list<cache_entry> collect_cache_info(const char *tmpl) noexcept = 0;
- virtual void generate_cache(JobData *job_data, const char *tmpl) noexcept = 0;
+ virtual std::forward_list<cache_entry> collect_cache_info(const std::filesystem::path& tmpl) noexcept = 0;
+ virtual void generate_cache(JobData *job_data, const std::filesystem::path& tmpl) noexcept = 0;
protected:
std::regex blacklist;