summaryrefslogtreecommitdiff
path: root/backend/job.cpp
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-05-20 17:53:57 +0200
committerEugen Wissner <belka@caraus.de>2026-05-20 17:53:57 +0200
commit76985de795f33f71684635ad5f14dc84aefea26e (patch)
treee8aed126b84b4ba3a76cf26fb9720c0f83eac594 /backend/job.cpp
parentc04278ff84c2c4d9c54bbd43c1542e4eace40419 (diff)
downloadkatja-76985de795f33f71684635ad5f14dc84aefea26e.tar.gz
Fix the backend test
Diffstat (limited to 'backend/job.cpp')
-rw-r--r--backend/job.cpp86
1 files changed, 35 insertions, 51 deletions
diff --git a/backend/job.cpp b/backend/job.cpp
index 9aaabc7..68a2090 100644
--- a/backend/job.cpp
+++ b/backend/job.cpp
@@ -15,6 +15,7 @@ module;
#include <curl/curl.h>
#include <glib/gstdio.h>
#include <sqlite3.h>
+#include <forward_list>
export module katja.job;
@@ -24,19 +25,18 @@ import katja.slackpkg;
namespace katja
{
-static GSList *repos = nullptr;
+static std::forward_list<std::unique_ptr<Pkgtools>> repos;
void pk_backend_initialize(GKeyFile *conf)
{
char *path, **groups;
int ret;
- gushort i;
- gsize groups_len;
+ std::uint8_t i;
+ std::size_t groups_len;
GFile *conf_file;
GFileInfo *file_info;
GKeyFile *key_conf;
GError *err = nullptr;
- void *repo = nullptr;
sqlite3 *db;
sqlite3_stmt *stmt;
@@ -107,9 +107,9 @@ void pk_backend_initialize(GKeyFile *conf)
if (g_key_file_has_key(key_conf, groups[i], "Priority", nullptr))
{
- repo = new Slackpkg(groups[i], mirror, i + 1, blacklist,
+ auto repo = std::make_unique<Slackpkg>(groups[i], mirror, i + 1, blacklist,
g_key_file_get_string_list(key_conf, groups[i], "Priority", nullptr, nullptr));
- repos = g_slist_append(repos, repo);
+ repos.emplace_front(std::move(repo));
}
g_free(mirror);
g_free(blacklist);
@@ -123,12 +123,7 @@ void pk_backend_destroy()
{
g_debug("backend: destroy");
- for (GSList *l = repos; l; l = g_slist_next(l))
- {
- delete static_cast<Pkgtools *>(l->data);
- }
-
- g_slist_free(repos);
+ repos.clear();
curl_global_cleanup();
}
@@ -257,7 +252,7 @@ void pk_backend_get_details(JobData *job_data, char **package_ids)
{
char *homepage = nullptr;
char** tokens;
- gsize i;
+ std::size_t i;
GString *desc;
GRegex *expr;
GMatchInfo *match_info;
@@ -392,10 +387,10 @@ void pk_backend_download_packages(JobData *job_data, char **package_ids, const c
sqlite3_bind_text(stmt, 4, tokens[3], -1, SQLITE_TRANSIENT);
if (sqlite3_step(stmt) == SQLITE_ROW)
{
- GSList *repo;
- if ((repo = g_slist_find_custom(repos, tokens[3], cmp_repo)))
+ auto repo = cmp_repo(std::begin(repos), std::end(repos), tokens[3]);
+ if (repo != std::end(repos))
{
- static_cast<Pkgtools *>(repo->data)->download(job_data, directory, tokens[0]);
+ (*repo)->download(job_data, directory, tokens[0]);
path = g_build_filename(directory, (char *) sqlite3_column_text(stmt, 1), nullptr);
to_strv[0] = path;
job_data->files(to_strv);
@@ -487,16 +482,13 @@ void pk_backend_install_packages(JobData *job_data, char **package_ids)
dest_dir_name = g_build_filename(LOCALSTATEDIR, "cache", "katja", "downloads", nullptr);
for (l = install_list, i = 0; l; l = g_slist_next(l), i++)
{
- char **tokens;
- GSList *repo;
-
job_data->set_percentage(percent_step * i);
- tokens = g_strsplit((char *)(l->data), ";", 4);
- repo = g_slist_find_custom(repos, tokens[3], cmp_repo);
+ char **tokens = g_strsplit((char *)(l->data), ";", 4);
+ auto repo = cmp_repo(std::begin(repos), std::end(repos), tokens[3]);
- if (repo)
+ if (repo != std::end(repos))
{
- static_cast<Pkgtools *>(repo->data)->download(job_data, dest_dir_name, tokens[0]);
+ (*repo)->download(job_data, dest_dir_name, tokens[0]);
}
g_strfreev(tokens);
}
@@ -505,16 +497,13 @@ void pk_backend_install_packages(JobData *job_data, char **package_ids)
/* Install the packages */
for (l = install_list; l; l = g_slist_next(l), i++)
{
- char **tokens;
- GSList *repo;
-
job_data->set_percentage(percent_step * i);
- tokens = g_strsplit((char *)(l->data), ";", 4);
- repo = g_slist_find_custom(repos, tokens[3], cmp_repo);
+ char **tokens = g_strsplit((char *)(l->data), ";", 4);
+ auto repo = cmp_repo(std::begin(repos), std::end(repos), tokens[3]);
- if (repo)
+ if (repo != std::end(repos))
{
- static_cast<Pkgtools *>(repo->data)->install(job_data, tokens[0]);
+ (*repo)->install(job_data, tokens[0]);
}
g_strfreev(tokens);
}
@@ -530,17 +519,15 @@ void pk_backend_remove_packages(JobData* job_data, char **package_ids)
{
char *cmd_line;
unsigned i;
- gdouble percent_step;
+ double percent_step;
GError *err = nullptr;
/* Add percent_step percents per removed package */
percent_step = 100.0 / g_strv_length(package_ids);
for (i = 0; package_ids[i]; i++)
{
- char **tokens;
-
job_data->set_percentage(percent_step * i);
- tokens = g_strsplit(package_ids[i], ";", 4);
+ char **tokens = g_strsplit(package_ids[i], ";", 4);
cmd_line = g_strconcat("/sbin/removepkg ", tokens[0], nullptr);
/* Pkgtools return always 0 */
@@ -611,7 +598,7 @@ void pk_backend_get_updates(JobData *job_data)
/* If there are more packages with the same name, remember the one from the
* repository with the lowest order. */
if ((sqlite3_step(stmt) == SQLITE_ROW)
- || g_slist_find_custom(repos, ((char *) sqlite3_column_text(stmt, 4)), cmp_repo))
+ || cmp_repo(std::begin(repos), std::end(repos), (const char *) sqlite3_column_text(stmt, 4)) != std::end(repos))
{
full_name = g_strdup((char *) sqlite3_column_text(stmt, 0));
@@ -656,11 +643,11 @@ void pk_backend_update_packages(JobData *job_data, char **package_ids)
for (i = 0; package_ids[i]; i++)
{
char **tokens = g_strsplit(package_ids[i], ";", 4);
- GSList *repo = g_slist_find_custom(repos, tokens[3], cmp_repo);
+ auto repo = cmp_repo(std::begin(repos), std::end(repos), tokens[3]);
- if (repo)
+ if (repo != std::end(repos))
{
- static_cast<Pkgtools *>(repo->data)->download(job_data, dest_dir_name, tokens[0]);
+ (*repo)->download(job_data, dest_dir_name, tokens[0]);
}
g_strfreev(tokens);
}
@@ -670,11 +657,11 @@ void pk_backend_update_packages(JobData *job_data, char **package_ids)
for (i = 0; package_ids[i]; i++)
{
char **tokens = g_strsplit(package_ids[i], ";", 4);
- GSList *repo = g_slist_find_custom(repos, tokens[3], cmp_repo);
+ auto repo = cmp_repo(std::begin(repos), std::end(repos), tokens[3]);
- if (repo)
+ if (repo != std::end(repos))
{
- static_cast<Pkgtools *>(repo->data)->install(job_data, tokens[0]);
+ (*repo)->install(job_data, tokens[0]);
}
g_strfreev(tokens);
}
@@ -684,7 +671,7 @@ void pk_backend_refresh_cache(JobData *job_data, bool force)
{
char *tmp_dir_name, *db_err, *path = nullptr;
int ret;
- GSList *file_list = nullptr;
+ std::forward_list<katja::cache_entry> file_list;
GFile *db_file = nullptr;
GFileInfo *file_info = nullptr;
GError *err = nullptr;
@@ -737,24 +724,21 @@ void pk_backend_refresh_cache(JobData *job_data, bool force)
}
// Get list of files that should be downloaded.
- for (GSList *l = repos; l; l = g_slist_next(l))
+ for (auto& l : repos)
{
- file_list = g_slist_concat(file_list,
- static_cast<Pkgtools *>(l->data)->collect_cache_info(tmp_dir_name));
+ file_list.prepend_range(l->collect_cache_info(tmp_dir_name));
}
/* Download repository */
- for (GSList *l = file_list; l; l = g_slist_next(l))
+ for (auto& l : file_list)
{
- get_file(&job_data->curl, static_cast<char **>(l->data)[0],
- static_cast<char **>(l->data)[1]);
+ get_file(&job_data->curl, l.first.c_str(), l.second.native().c_str());
}
- g_slist_free_full(file_list, (GDestroyNotify) g_strfreev);
/* Refresh cache */
- for (GSList *l = repos; l; l = g_slist_next(l))
+ for (auto& l : repos)
{
- static_cast<Pkgtools *>(l->data)->generate_cache(job_data, tmp_dir_name);
+ l->generate_cache(job_data, tmp_dir_name);
}
out: