diff options
Diffstat (limited to 'backend/slackpkg.cpp')
| -rw-r--r-- | backend/slackpkg.cpp | 71 |
1 files changed, 21 insertions, 50 deletions
diff --git a/backend/slackpkg.cpp b/backend/slackpkg.cpp index fd7ea22..d546b5e 100644 --- a/backend/slackpkg.cpp +++ b/backend/slackpkg.cpp @@ -16,6 +16,8 @@ module; #include <string> #include <regex> #include <vector> +#include <forward_list> +#include <filesystem> export module katja.slackpkg; @@ -47,30 +49,12 @@ public: { this->blacklist = std::regex(blacklist); } - for (char **cur_priority = priority; *cur_priority; cur_priority++) + if (priority != nullptr) { - this->priority.emplace_back(*cur_priority); - } - // Initialize category map - if (cat_map == nullptr) - { - cat_map = g_hash_table_new(g_str_hash, g_str_equal); - g_hash_table_insert(cat_map, (void *) "a", (void *) "system"); - g_hash_table_insert(cat_map, (void *) "ap", (void *) "admin-tools"); - g_hash_table_insert(cat_map, (void *) "d", (void *) "programming"); - g_hash_table_insert(cat_map, (void *) "e", (void *) "programming"); - g_hash_table_insert(cat_map, (void *) "f", (void *) "documentation"); - g_hash_table_insert(cat_map, (void *) "k", (void *) "system"); - g_hash_table_insert(cat_map, (void *) "kde", (void *) "desktop-kde"); - g_hash_table_insert(cat_map, (void *) "kdei", (void *) "localization"); - g_hash_table_insert(cat_map, (void *) "l", (void *) "system"); - g_hash_table_insert(cat_map, (void *) "n", (void *) "network"); - g_hash_table_insert(cat_map, (void *) "t", (void *) "publishing"); - g_hash_table_insert(cat_map, (void *) "tcl", (void *) "system"); - g_hash_table_insert(cat_map, (void *) "x", (void *) "desktop-other"); - g_hash_table_insert(cat_map, (void *) "xap", (void *) "accessories"); - g_hash_table_insert(cat_map, (void *) "xfce", (void *) "desktop-xfce"); - g_hash_table_insert(cat_map, (void *) "y", (void *) "games"); + for (char **cur_priority = priority; *cur_priority; cur_priority++) + { + this->priority.emplace_back(*cur_priority); + } } } @@ -83,11 +67,11 @@ public: * * Returns: List of files needed for building the cache. **/ - GSList *collect_cache_info(const char *tmpl) noexcept + std::forward_list<cache_entry> collect_cache_info(const char *tmpl) noexcept { CURL *curl = nullptr; - char **source_dest; - GSList *file_list = nullptr; + cache_entry source_dest; + std::forward_list<cache_entry> file_list; GFile *tmp_dir, *repo_tmp_dir; /* Create the temporary directory for the repository */ @@ -98,34 +82,25 @@ public: /* Download PACKAGES.TXT. These files are most important, break if some of them couldn't be found */ for (const std::string& current_priority : this->priority) { - source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *))); - source_dest[0] = g_strconcat(this->mirror.c_str(), current_priority.c_str(), "/PACKAGES.TXT", nullptr); - source_dest[1] = g_build_filename(tmpl, this->name.c_str(), "PACKAGES.TXT", nullptr); - source_dest[2] = nullptr; + source_dest.first = this->mirror + current_priority + "/PACKAGES.TXT"; + source_dest.second = std::filesystem::path(tmpl) / this->name / "PACKAGES.TXT"; - if (get_file(&curl, source_dest[0], nullptr) == CURLE_OK) + if (get_file(&curl, source_dest.first.c_str(), nullptr) == CURLE_OK) { - file_list = g_slist_prepend(file_list, source_dest); + file_list.emplace_front(std::move(source_dest)); } else { - g_strfreev(source_dest); - g_slist_free_full(file_list, (GDestroyNotify)g_strfreev); goto out; } /* Download file lists if available */ - source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *))); - source_dest[0] = g_strconcat(this->mirror.c_str(), current_priority.c_str(), "/MANIFEST.bz2", nullptr); - source_dest[1] = g_strconcat(tmpl, "/", this->name.c_str(), "/", *current_priority.c_str(), "-MANIFEST.bz2", nullptr); - source_dest[2] = nullptr; - if (get_file(&curl, source_dest[0], nullptr) == CURLE_OK) - { - file_list = g_slist_prepend(file_list, source_dest); - } - else + source_dest.first = this->mirror + current_priority + "/MANIFEST.bz2"; + source_dest.second = std::filesystem::path(tmpl) / this->name / (current_priority + "-MANIFEST.bz2"); + + if (get_file(&curl, source_dest.first.c_str(), nullptr) == CURLE_OK) { - g_strfreev(source_dest); + file_list.emplace_front(std::move(source_dest)); } } out: @@ -154,7 +129,7 @@ public: char **pkg_tokens = nullptr; char *query = nullptr, *filename = nullptr, *location = nullptr, *summary = nullptr, *line, *packages_txt; unsigned pkg_compressed = 0, pkg_uncompressed = 0; - gushort pkg_name_len; + std::uint8_t pkg_name_len; GString *desc; GFile *list_file; GFileInputStream *fin = nullptr; @@ -279,12 +254,9 @@ public: { /* Get the package group based on its location */ const char *cat = g_strrstr(location, "/"); - if (cat) /* Else cat = nullptr */ - { - cat = static_cast<const char *>(g_hash_table_lookup(cat_map, cat + 1)); - } if (cat) { + ++cat; statement = insert_statement; sqlite3_bind_text(insert_statement, 12, cat, -1, SQLITE_TRANSIENT); } @@ -349,7 +321,6 @@ public: } private: - static inline GHashTable *cat_map{ nullptr }; static const std::size_t max_buf_size = 8192; std::vector<std::string> priority; |
