Remove dropline backend support
Test / build (push) Successful in 43s

This commit is contained in:
2026-05-04 15:37:47 +02:00
parent d84e192ae9
commit 2def836b73
12 changed files with 829 additions and 1264 deletions
+1
View File
@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 4.0.0)
project(Katja LANGUAGES CXX) project(Katja LANGUAGES CXX)
include(CTest) include(CTest)
include(GNUInstallDirs)
option(KATJA_BUILD_CLI "Build command line interface" ON) option(KATJA_BUILD_CLI "Build command line interface" ON)
+2 -2
View File
@@ -7,8 +7,8 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)
add_library(backend) add_library(backend)
target_sources(backend target_sources(backend
INTERFACE job.h utils.h pkgtools.h slackpkg.h dl.h INTERFACE job.h utils.h pkgtools.h slackpkg.h
PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc dl.cc PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc
) )
configure_file(config.h.in ${CMAKE_BINARY_DIR}/generated/config.h) configure_file(config.h.in ${CMAKE_BINARY_DIR}/generated/config.h)
-293
View File
@@ -1,293 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <sqlite3.h>
#include <stdlib.h>
#include <gio/gio.h>
#include "dl.h"
#include "utils.h"
namespace katja
{
/**
* katja::Dl::collect_cache_info:
* @tmpl: temporary directory for downloading the files.
*
* Download files needed to get the information like the list of packages
* in available repositories, updates, package descriptions and so on.
*
* Returns: List of files needed for building the cache.
**/
GSList *
Dl::collect_cache_info (const char *tmpl) noexcept
{
CURL *curl = nullptr;
GSList *file_list = nullptr;
GFile *tmp_dir, *repo_tmp_dir;
/* Create the temporary directory for the repository */
tmp_dir = g_file_new_for_path(tmpl);
repo_tmp_dir = g_file_get_child(tmp_dir, this->get_name ());
g_file_make_directory(repo_tmp_dir, nullptr, nullptr);
/* There is no ChangeLog yet to check if there are updates or not. Just mark the index file for download */
auto source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *)));
source_dest[0] = g_strdup(this->index_file);
source_dest[1] = g_build_filename(tmpl,
this->get_name (),
"IndexFile",
nullptr);
source_dest[2] = nullptr;
/* Check if the remote file can be found */
if (get_file(&curl, source_dest[0], nullptr))
{
g_strfreev(source_dest);
}
else
{
file_list = g_slist_append(file_list, source_dest);
}
g_object_unref(repo_tmp_dir);
g_object_unref(tmp_dir);
if (curl)
{
curl_easy_cleanup(curl);
}
return file_list;
}
/**
* katja::Dl::generate_cache:
* @job_data: A #JobData.
* @tmpl: temporary directory for downloading the files.
*
* Download files needed to get the information like the list of packages
* in available repositories, updates, package descriptions and so on.
*
* Returns: List of files needed for building the cache.
**/
void
Dl::generate_cache(JobData *job_data, const char *tmpl) noexcept
{
char **line_tokens, **pkg_tokens, *line, *collection_name = nullptr, *list_filename;
bool skip = false;
GFile *list_file;
GFileInputStream *fin;
GDataInputStream *data_in = nullptr;
sqlite3_stmt *stmt = nullptr;
/* Check if the temporary directory for this repository exists. If so the file metadata have to be generated */
list_filename = g_build_filename(tmpl,
this->get_name (),
"IndexFile",
nullptr);
list_file = g_file_new_for_path(list_filename);
if (!(fin = g_file_read(list_file, nullptr, nullptr)))
{
goto out;
}
data_in = g_data_input_stream_new(G_INPUT_STREAM(fin));
/* Remove the old entries from this repository */
if (sqlite3_prepare_v2(job_data->db,
"DELETE FROM repos WHERE repo LIKE @repo",
-1,
&stmt,
nullptr) == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, this->get_name (), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
if (sqlite3_prepare_v2(job_data->db,
"INSERT INTO repos (repo_order, repo) VALUES (@repo_order, @repo)",
-1,
&stmt,
nullptr) != SQLITE_OK)
{
goto out;
}
sqlite3_bind_int(stmt, 1, this->get_order ());
sqlite3_bind_text(stmt, 2, this->get_name (), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt);
if (sqlite3_finalize(stmt) != SQLITE_OK)
{
goto out;
}
/* Insert new records */
if ((sqlite3_prepare_v2(job_data->db,
"INSERT INTO pkglist (full_name, name, ver, arch, "
"summary, desc, compressed, uncompressed, cat, repo_order, ext) "
"VALUES (@full_name, @name, @ver, @arch, @summary, "
"@desc, @compressed, @uncompressed, @cat, @repo_order, @ext)",
-1,
&stmt,
nullptr) != SQLITE_OK))
{
goto out;
}
sqlite3_exec(job_data->db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
while ((line = g_data_input_stream_read_line(data_in, nullptr, nullptr, nullptr)))
{
line_tokens = g_strsplit(line, ":", 0);
if ((g_strv_length(line_tokens) > 6)
&& !this->is_blacklisted (line_tokens[0]))
{
pkg_tokens = split_package_name(line_tokens[0]);
/* If the split_package_name doesn't return a full name and an
* extension, it is a collection. We save its name in this case */
if (pkg_tokens[3])
{
sqlite3_bind_text(stmt, 1, pkg_tokens[3], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 9, "desktop-gnome", -1, SQLITE_STATIC);
if (g_strcmp0(line_tokens[1], "obsolete"))
{
sqlite3_bind_text(stmt, 11, pkg_tokens[4], -1, SQLITE_TRANSIENT);
}
else
{
sqlite3_bind_text(stmt, 11, "obsolete", -1, SQLITE_STATIC);
}
}
else if (!collection_name)
{
collection_name = g_strdup(pkg_tokens[0]);
sqlite3_bind_text(stmt, 1, line_tokens[0], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 9, "collections", -1, SQLITE_STATIC);
sqlite3_bind_null(stmt, 11);
}
else
{
skip = true; /* Skip other candidates for collections */
}
if (skip)
{
skip = false;
}
else
{
sqlite3_bind_text(stmt, 2, pkg_tokens[0], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, pkg_tokens[1], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 4, pkg_tokens[2], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 5, line_tokens[2], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 6, line_tokens[2], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 7, atoi(line_tokens[5]));
sqlite3_bind_int(stmt, 8, atoi(line_tokens[5]));
sqlite3_bind_int(stmt, 10, this->get_order ());
sqlite3_step(stmt);
sqlite3_clear_bindings(stmt);
sqlite3_reset(stmt);
}
g_strfreev(pkg_tokens);
}
g_strfreev(line_tokens);
g_free(line);
}
/* Create a collection entry */
if (collection_name && g_seekable_seek(G_SEEKABLE(data_in), 0, G_SEEK_SET, nullptr, nullptr)
&& (sqlite3_prepare_v2(job_data->db,
"INSERT INTO collections (name, repo_order, collection_pkg) "
"VALUES (@name, @repo_order, @collection_pkg)",
-1,
&stmt,
nullptr) == SQLITE_OK))
{
while ((line = g_data_input_stream_read_line(data_in, nullptr, nullptr, nullptr)))
{
line_tokens = g_strsplit(line, ":", 0);
if ((g_strv_length(line_tokens) > 6)
&& !this->is_blacklisted (line_tokens[0]))
{
pkg_tokens = split_package_name(line_tokens[0]);
/* If not a collection itself */
if (pkg_tokens[3]) /* Save this package as a part of the collection */
{
sqlite3_bind_text(stmt, 1, collection_name, -1, SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 2, this->get_order ());
sqlite3_bind_text(stmt, 3, pkg_tokens[0], -1, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_clear_bindings(stmt);
sqlite3_reset(stmt);
}
g_strfreev(pkg_tokens);
}
g_strfreev(line_tokens);
g_free(line);
}
sqlite3_finalize(stmt);
}
g_free(collection_name);
sqlite3_exec(job_data->db, "END TRANSACTION", nullptr, nullptr, nullptr);
out:
if (data_in)
{
g_object_unref(data_in);
}
if (fin)
{
g_object_unref(fin);
}
g_object_unref(list_file);
g_free(list_filename);
}
Dl::~Dl () noexcept
{
if (this->blacklist)
{
g_regex_unref (this->blacklist);
}
g_free (this->name);
g_free (this->mirror);
g_free (this->index_file);
}
/**
* katja::Dl::Dl:
* @name: Repository name.
* @mirror: Repository mirror.
* @order: Repository order.
* @blacklist: Repository blacklist.
* @index_file: The index file URL.
*
* Constructor.
*
* Return value: New #katja::Dl.
**/
Dl::Dl (const char *name, const char *mirror,
std::uint8_t order, const char *blacklist, char *index_file) noexcept
{
GRegex *regex;
if (blacklist)
{
regex = static_cast<GRegex *> (g_regex_new (blacklist,
G_REGEX_OPTIMIZE, static_cast<GRegexMatchFlags> (0), nullptr));
}
else
{
regex = nullptr;
}
this->name = g_strdup (name);
this->mirror = g_strdup (mirror);
this->order = order;
this->blacklist = regex;
this->index_file = index_file;
}
}
-28
View File
@@ -1,28 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <cstdint>
#include "pkgtools.h"
#include "utils.h"
namespace katja
{
class Dl final : public Pkgtools
{
public:
Dl (const char *name, const char *mirror,
std::uint8_t order, const char *blacklist, char *index_file) noexcept;
~Dl () noexcept;
GSList *collect_cache_info (const char *tmpl) noexcept;
void generate_cache (JobData *job_data, const char *tmpl) noexcept;
private:
char *index_file;
};
}
+572 -648
View File
File diff suppressed because it is too large Load Diff
+6 -8
View File
@@ -6,16 +6,15 @@
#pragma once #pragma once
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include "utils.h"
void pk_backend_initialize(GKeyFile *conf); void pk_backend_initialize(GKeyFile *conf);
void pk_backend_destroy(); void pk_backend_destroy();
void pk_backend_start_job(PkBackendJob *job); katja::JobData *pk_backend_start_job();
void pk_backend_stop_job(PkBackendJob *job); void pk_backend_stop_job(katja::JobData *job_data)
void pk_backend_search_names(PkBackendJob *job, char **values); void pk_backend_search_thread(PkBackendJob *job, GVariant *params, const char *user_data);
void pk_backend_search_details(PkBackendJob *job, char **values);
void pk_backend_search_groups(PkBackendJob *job, char **values);
void pk_backend_search_files(PkBackendJob *job, char **values); void pk_backend_search_files(PkBackendJob *job, char **values);
void pk_backend_get_details(PkBackendJob *job, char **package_ids); void pk_backend_get_details(PkBackendJob *job, char **package_ids);
@@ -26,6 +25,5 @@ void pk_backend_install_packages(PkBackendJob *job, char **package_ids);
void pk_backend_remove_packages(PkBackendJob *job, char **package_ids); void pk_backend_remove_packages(PkBackendJob *job, char **package_ids);
void pk_backend_get_updates(PkBackendJob *job); void pk_backend_get_updates(PkBackendJob *job);
void pk_backend_update_packages(PkBackendJob *job, char **package_ids); void pk_backend_update_packages(katja::JobData *job_data, char **package_ids);
void pk_backend_refresh_cache(PkBackendJob *job, bool force); void pk_backend_refresh_cache(katja::JobData *job, bool force);
void pk_backend_get_update_detail(PkBackendJob *job, char **package_ids);
+74 -90
View File
@@ -12,7 +12,7 @@ namespace katja
{ {
/** /**
* katja::Pkgtools::download: * katja::Pkgtools::download:
* @job: A #PkBackendJob. * @job_data: A #JobData.
* @dest_dir_name: Destination directory. * @dest_dir_name: Destination directory.
* @pkg_name: Package name. * @pkg_name: Package name.
* *
@@ -20,57 +20,47 @@ namespace katja
* *
* Returns: %TRUE on success, %FALSE otherwise. * Returns: %TRUE on success, %FALSE otherwise.
**/ **/
bool bool Pkgtools::download(JobData *job_data, char *dest_dir_name, char *pkg_name) noexcept
Pkgtools::download (JobData *job_data,
char *dest_dir_name, char *pkg_name) noexcept
{ {
char *dest_filename, *source_url; char *dest_filename, *source_url;
bool ret = false; bool ret = false;
sqlite3_stmt *statement = nullptr; sqlite3_stmt *statement = nullptr;
CURL *curl = nullptr; CURL *curl = nullptr;
if ((sqlite3_prepare_v2(job_data->db, if ((sqlite3_prepare_v2(job_data->db,
"SELECT location, (full_name || '.' || ext) FROM pkglist " "SELECT location, (full_name || '.' || ext) FROM pkglist "
"WHERE name LIKE @name AND repo_order = @repo_order", "WHERE name LIKE @name AND repo_order = @repo_order",
-1, -1,
&statement, &statement,
nullptr) != SQLITE_OK)) nullptr) != SQLITE_OK))
return false; {
return false;
}
sqlite3_bind_text(statement, 1, pkg_name, -1, SQLITE_TRANSIENT);
sqlite3_bind_int(statement, 2, this->get_order());
sqlite3_bind_text(statement, 1, pkg_name, -1, SQLITE_TRANSIENT); if (sqlite3_step(statement) == SQLITE_ROW)
sqlite3_bind_int(statement, 2, this->get_order ()); {
dest_filename = g_build_filename(dest_dir_name, sqlite3_column_text(statement, 1), nullptr);
source_url = g_strconcat(this->get_mirror(),
sqlite3_column_text(statement, 0),
"/",
sqlite3_column_text(statement, 1),
nullptr);
if (sqlite3_step(statement) == SQLITE_ROW) ret = g_file_test(dest_filename, G_FILE_TEST_EXISTS)
{ || get_file(&curl, source_url, dest_filename) == CURLE_OK;
dest_filename = g_build_filename(dest_dir_name, sqlite3_column_text(statement, 1), nullptr);
source_url = g_strconcat(this->get_mirror (),
sqlite3_column_text(statement, 0),
"/",
sqlite3_column_text(statement, 1),
nullptr);
if (!g_file_test(dest_filename, G_FILE_TEST_EXISTS)) if (curl)
{ {
if (get_file(&curl, source_url, dest_filename) == CURLE_OK) curl_easy_cleanup(curl);
{ }
ret = true; g_free(source_url);
} g_free(dest_filename);
} }
else sqlite3_finalize(statement);
{
ret = true;
}
if (curl) return ret;
{
curl_easy_cleanup(curl);
}
g_free(source_url);
g_free(dest_filename);
}
sqlite3_finalize(statement);
return ret;
} }
/** /**
@@ -80,43 +70,42 @@ Pkgtools::download (JobData *job_data,
* *
* Install a package. * Install a package.
**/ **/
void void Pkgtools::install(JobData *job_data, char *pkg_name) noexcept
Pkgtools::install (JobData *job_data, char *pkg_name) noexcept
{ {
char *pkg_filename, *cmd_line; char *pkg_filename, *cmd_line;
sqlite3_stmt *statement = nullptr; sqlite3_stmt *statement = nullptr;
if ((sqlite3_prepare_v2(job_data->db, if ((sqlite3_prepare_v2(job_data->db,
"SELECT (full_name || '.' || ext) FROM pkglist " "SELECT (full_name || '.' || ext) FROM pkglist "
"WHERE name LIKE @name AND repo_order = @repo_order", "WHERE name LIKE @name AND repo_order = @repo_order",
-1, -1,
&statement, &statement,
nullptr) != SQLITE_OK)) nullptr) != SQLITE_OK))
{ {
return; return;
} }
sqlite3_bind_text(statement, 1, pkg_name, -1, SQLITE_TRANSIENT); sqlite3_bind_text(statement, 1, pkg_name, -1, SQLITE_TRANSIENT);
sqlite3_bind_int(statement, 2, this->get_order ()); sqlite3_bind_int(statement, 2, this->get_order());
if (sqlite3_step(statement) == SQLITE_ROW) if (sqlite3_step(statement) == SQLITE_ROW)
{ {
pkg_filename = g_build_filename(LOCALSTATEDIR, pkg_filename = g_build_filename(LOCALSTATEDIR,
"cache", "cache",
"PackageKit", "PackageKit",
"downloads", "downloads",
sqlite3_column_text(statement, 0), sqlite3_column_text(statement, 0),
nullptr); nullptr);
cmd_line = g_strconcat("/sbin/upgradepkg --install-new ", pkg_filename, nullptr); cmd_line = g_strconcat("/sbin/upgradepkg --install-new ", pkg_filename, nullptr);
g_spawn_command_line_sync(cmd_line, nullptr, nullptr, nullptr, nullptr); g_spawn_command_line_sync(cmd_line, nullptr, nullptr, nullptr, nullptr);
g_free(cmd_line); g_free(cmd_line);
g_free(pkg_filename); g_free(pkg_filename);
} }
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
Pkgtools::~Pkgtools () noexcept Pkgtools::~Pkgtools() noexcept
{ {
} }
@@ -127,10 +116,9 @@ Pkgtools::~Pkgtools () noexcept
* *
* Returns: Repository name. * Returns: Repository name.
**/ **/
const char * const char *Pkgtools::get_name() const noexcept
Pkgtools::get_name () const noexcept
{ {
return this->name; return this->name;
} }
/** /**
@@ -140,10 +128,9 @@ Pkgtools::get_name () const noexcept
* *
* Returns: Repository mirror. * Returns: Repository mirror.
**/ **/
const char * const char *Pkgtools::get_mirror() const noexcept
Pkgtools::get_mirror () const noexcept
{ {
return this->mirror; return this->mirror;
} }
/** /**
@@ -153,10 +140,9 @@ Pkgtools::get_mirror () const noexcept
* *
* Returns: Repository order. * Returns: Repository order.
**/ **/
guint8 guint8 Pkgtools::get_order() const noexcept
Pkgtools::get_order () const noexcept
{ {
return this->order; return this->order;
} }
/** /**
@@ -167,12 +153,10 @@ Pkgtools::get_order () const noexcept
* *
* Returns: %TRUE if the package is blacklisted, %FALSE otherwise. * Returns: %TRUE if the package is blacklisted, %FALSE otherwise.
**/ **/
bool bool Pkgtools::is_blacklisted(const char *pkg) const noexcept
Pkgtools::is_blacklisted (const char *pkg) const noexcept
{ {
return this->blacklist return this->blacklist
&& g_regex_match (this->blacklist, && g_regex_match (this->blacklist, pkg, static_cast<GRegexMatchFlags>(0), nullptr);
pkg, static_cast<GRegexMatchFlags> (0), nullptr);
} }
} }
+12 -15
View File
@@ -14,26 +14,23 @@ namespace katja
class Pkgtools class Pkgtools
{ {
public: public:
const char *get_name () const noexcept; const char *get_name() const noexcept;
const char *get_mirror () const noexcept; const char *get_mirror() const noexcept;
std::uint8_t get_order () const noexcept; std::uint8_t get_order() const noexcept;
bool is_blacklisted (const char *pkg) const noexcept; bool is_blacklisted(const char *pkg) const noexcept;
virtual ~Pkgtools () noexcept; virtual ~Pkgtools() noexcept;
bool download (JobData *job_data, bool download(JobData *job_data, char *dest_dir_name, char *pkg_name) noexcept;
char *dest_dir_name, char *pkg_name) noexcept; void install(JobData *job_data, char *pkg_name) noexcept;
void install (JobData *job_data, char *pkg_name) noexcept;
virtual GSList *collect_cache_info (const char *tmpl) noexcept = 0; virtual GSList *collect_cache_info (const char *tmpl) noexcept = 0;
virtual void generate_cache (JobData *job_data, virtual void generate_cache(JobData *job_data, const char *tmpl) noexcept = 0;
const char *tmpl) noexcept = 0;
protected: protected:
char *name = nullptr; char *name = nullptr;
char *mirror = nullptr; char *mirror = nullptr;
std::uint8_t order; std::uint8_t order;
GRegex *blacklist = nullptr; GRegex *blacklist = nullptr;
}; };
} }
+16 -29
View File
@@ -12,15 +12,14 @@ GHashTable *Slackpkg::cat_map = nullptr;
/* /*
* katja::Slackpkg::manifest: * katja::Slackpkg::manifest:
* @job: a #PkBackendJob. * @job: a #JobData.
* @tmpl: temporary directory. * @tmpl: temporary directory.
* @filename: manifest filename * @filename: manifest filename
* *
* Parse the manifest file and save the file list in the database. * Parse the manifest file and save the file list in the database.
*/ */
void void
Slackpkg::manifest (PkBackendJob *job, Slackpkg::manifest(JobData *job_data, const char *tmpl, char *filename) noexcept
const char *tmpl, char *filename) noexcept
{ {
FILE *manifest; FILE *manifest;
int err, read_len; int err, read_len;
@@ -32,10 +31,9 @@ Slackpkg::manifest (PkBackendJob *job,
GRegex *pkg_expr = nullptr, *file_expr = nullptr; GRegex *pkg_expr = nullptr, *file_expr = nullptr;
GMatchInfo *match_info; GMatchInfo *match_info;
sqlite3_stmt *statement = nullptr; sqlite3_stmt *statement = nullptr;
auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job));
path = g_build_filename(tmpl, path = g_build_filename(tmpl,
this->get_name (), this->get_name(),
filename, filename,
nullptr); nullptr);
manifest = fopen(path, "rb"); manifest = fopen(path, "rb");
@@ -169,19 +167,19 @@ Slackpkg::collect_cache_info (const char *tmpl) noexcept
/* Create the temporary directory for the repository */ /* Create the temporary directory for the repository */
tmp_dir = g_file_new_for_path(tmpl); tmp_dir = g_file_new_for_path(tmpl);
repo_tmp_dir = g_file_get_child(tmp_dir, this->get_name ()); repo_tmp_dir = g_file_get_child(tmp_dir, this->get_name());
g_file_make_directory(repo_tmp_dir, nullptr, nullptr); g_file_make_directory(repo_tmp_dir, nullptr, nullptr);
/* Download PACKAGES.TXT. These files are most important, break if some of them couldn't be found */ /* Download PACKAGES.TXT. These files are most important, break if some of them couldn't be found */
for (char **cur_priority = this->priority; *cur_priority; cur_priority++) for (char **cur_priority = this->priority; *cur_priority; cur_priority++)
{ {
source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *))); source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *)));
source_dest[0] = g_strconcat(this->get_mirror (), source_dest[0] = g_strconcat(this->get_mirror(),
*cur_priority, *cur_priority,
"/PACKAGES.TXT", "/PACKAGES.TXT",
nullptr); nullptr);
source_dest[1] = g_build_filename(tmpl, source_dest[1] = g_build_filename(tmpl,
this->get_name (), this->get_name(),
"PACKAGES.TXT", "PACKAGES.TXT",
nullptr); nullptr);
source_dest[2] = nullptr; source_dest[2] = nullptr;
@@ -199,12 +197,12 @@ Slackpkg::collect_cache_info (const char *tmpl) noexcept
/* Download file lists if available */ /* Download file lists if available */
source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *))); source_dest = static_cast<char **> (g_malloc_n(3, sizeof(char *)));
source_dest[0] = g_strconcat(this->get_mirror (), source_dest[0] = g_strconcat(this->get_mirror(),
*cur_priority, *cur_priority,
"/MANIFEST.bz2", "/MANIFEST.bz2",
nullptr); nullptr);
source_dest[1] = g_strconcat(tmpl, source_dest[1] = g_strconcat(tmpl,
"/", this->get_name (), "/", this->get_name(),
"/", *cur_priority, "-MANIFEST.bz2", "/", *cur_priority, "-MANIFEST.bz2",
nullptr); nullptr);
source_dest[2] = nullptr; source_dest[2] = nullptr;
@@ -239,7 +237,7 @@ out:
* Returns: List of files needed for building the cache. * Returns: List of files needed for building the cache.
**/ **/
void void
Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept Slackpkg::generate_cache(JobData *job_data, const char *tmpl) noexcept
{ {
char **pkg_tokens = nullptr; char **pkg_tokens = nullptr;
char *query = nullptr, *filename = nullptr, *location = nullptr, *summary = nullptr, *line, *packages_txt; char *query = nullptr, *filename = nullptr, *location = nullptr, *summary = nullptr, *line, *packages_txt;
@@ -252,10 +250,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
sqlite3_stmt *insert_statement = nullptr, *update_statement = nullptr, *insert_default_statement = nullptr, *statement; sqlite3_stmt *insert_statement = nullptr, *update_statement = nullptr, *insert_default_statement = nullptr, *statement;
/* Check if the temporary directory for this repository exists, then the file metadata have to be generated */ /* Check if the temporary directory for this repository exists, then the file metadata have to be generated */
packages_txt = g_build_filename(tmpl, packages_txt = g_build_filename(tmpl, this->get_name(), "PACKAGES.TXT", nullptr);
this->get_name (),
"PACKAGES.TXT",
nullptr);
list_file = g_file_new_for_path(packages_txt); list_file = g_file_new_for_path(packages_txt);
fin = g_file_read(list_file, nullptr, nullptr); fin = g_file_read(list_file, nullptr, nullptr);
g_object_unref(list_file); g_object_unref(list_file);
@@ -271,11 +266,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
&statement, &statement,
nullptr) == SQLITE_OK) nullptr) == SQLITE_OK)
{ {
sqlite3_bind_text(statement, sqlite3_bind_text(statement, 1, this->get_name(), -1, SQLITE_TRANSIENT);
1,
this->get_name (),
-1,
SQLITE_TRANSIENT);
sqlite3_step(statement); sqlite3_step(statement);
sqlite3_finalize(statement); sqlite3_finalize(statement);
} }
@@ -287,12 +278,8 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
{ {
goto out; goto out;
} }
sqlite3_bind_int(statement, 1, this->get_order ()); sqlite3_bind_int(statement, 1, this->get_order());
sqlite3_bind_text(statement, sqlite3_bind_text(statement, 2, this->get_name(), -1, SQLITE_TRANSIENT);
2,
this->get_name (),
-1,
SQLITE_TRANSIENT);
sqlite3_step(statement); sqlite3_step(statement);
sqlite3_finalize(statement); sqlite3_finalize(statement);
@@ -320,7 +307,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
"ext = @ext, location = @location, summary = @summary, " "ext = @ext, location = @location, summary = @summary, "
"desc = @desc, compressed = @compressed, uncompressed = @uncompressed " "desc = @desc, compressed = @compressed, uncompressed = @uncompressed "
"WHERE name LIKE @name AND repo_order = %u", "WHERE name LIKE @name AND repo_order = %u",
this->get_order ()); this->get_order());
if (sqlite3_prepare_v2(job_data->db, query, -1, &update_statement, nullptr) != SQLITE_OK) if (sqlite3_prepare_v2(job_data->db, query, -1, &update_statement, nullptr) != SQLITE_OK)
{ {
goto out; goto out;
@@ -392,7 +379,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
{ {
statement = insert_default_statement; statement = insert_default_statement;
} }
sqlite3_bind_int(statement, 11, this->get_order ()); sqlite3_bind_int(statement, 11, this->get_order());
} }
else /* Update package information if it is a patch */ else /* Update package information if it is a patch */
{ {
@@ -433,7 +420,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
for (char **p = this->priority; *p; p++) for (char **p = this->priority; *p; p++)
{ {
filename = g_strconcat(*p, "-MANIFEST.bz2", nullptr); filename = g_strconcat(*p, "-MANIFEST.bz2", nullptr);
manifest (job, tmpl, filename); manifest(job_data, tmpl, filename);
g_free(filename); g_free(filename);
} }
out: out:
+2 -3
View File
@@ -20,15 +20,14 @@ public:
~Slackpkg () noexcept; ~Slackpkg () noexcept;
GSList *collect_cache_info (const char *tmpl) noexcept; GSList *collect_cache_info (const char *tmpl) noexcept;
void generate_cache (JobData *job_data, const char *tmpl) noexcept; void generate_cache(JobData *job_data, const char *tmpl) noexcept;
private: private:
static GHashTable *cat_map; static GHashTable *cat_map;
static const std::size_t max_buf_size = 8192; static const std::size_t max_buf_size = 8192;
char **priority = nullptr; char **priority = nullptr;
void manifest (PkBackendJob *job, void manifest(JobData *job_data, const char *tmpl, char *filename) noexcept;
const char *tmpl, char *filename) noexcept;
}; };
} }
+135 -141
View File
@@ -22,130 +22,126 @@ namespace katja
* *
* Returns: CURLE_OK (zero) on success, non-zero otherwise. * Returns: CURLE_OK (zero) on success, non-zero otherwise.
**/ **/
CURLcode CURLcode get_file(CURL **curl, char *source_url, char *dest)
get_file (CURL **curl, char *source_url, char *dest)
{ {
char *dest_dir_name; char *dest_dir_name;
FILE *fout = nullptr; FILE *fout = nullptr;
CURLcode ret; CURLcode ret;
glong response_code; glong response_code;
if ((*curl == nullptr) && (!(*curl = curl_easy_init()))) if ((*curl == nullptr) && (!(*curl = curl_easy_init())))
{ {
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
} }
curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(*curl, CURLOPT_URL, source_url); curl_easy_setopt(*curl, CURLOPT_URL, source_url);
if (dest == nullptr) if (dest == nullptr)
{ {
curl_easy_setopt(*curl, CURLOPT_NOBODY, 1L); curl_easy_setopt(*curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(*curl, CURLOPT_HEADER, 1L); curl_easy_setopt(*curl, CURLOPT_HEADER, 1L);
ret = curl_easy_perform(*curl); ret = curl_easy_perform(*curl);
curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &response_code); curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &response_code);
if (response_code != 200) if (response_code != 200)
{ {
ret = CURLE_REMOTE_FILE_NOT_FOUND; ret = CURLE_REMOTE_FILE_NOT_FOUND;
} }
} }
else else
{ {
if (g_file_test(dest, G_FILE_TEST_IS_DIR)) if (g_file_test(dest, G_FILE_TEST_IS_DIR))
{ {
dest_dir_name = dest; dest_dir_name = dest;
dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), nullptr); dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), nullptr);
g_free(dest_dir_name); g_free(dest_dir_name);
} }
if ((fout = fopen(dest, "ab")) == nullptr) if ((fout = fopen(dest, "ab")) == nullptr)
{ {
return CURLE_WRITE_ERROR; return CURLE_WRITE_ERROR;
} }
curl_easy_setopt(*curl, CURLOPT_WRITEDATA, fout); curl_easy_setopt(*curl, CURLOPT_WRITEDATA, fout);
ret = curl_easy_perform(*curl); ret = curl_easy_perform(*curl);
} }
curl_easy_reset(*curl); curl_easy_reset(*curl);
if (fout != nullptr) if (fout != nullptr)
{ {
fclose(fout); fclose(fout);
} }
return ret; return ret;
} }
/** /**
* katja::split_package_name: * katja::split_package_name:
* Got the name of a package, without version-arch-release data. * Got the name of a package, without version-arch-release data.
**/ **/
char ** char **split_package_name(const char *pkg_filename)
split_package_name (const char *pkg_filename)
{ {
char *pkg_full_name; char *pkg_full_name;
char **pkg_tokens; char **pkg_tokens;
g_return_val_if_fail(pkg_filename != nullptr, nullptr); g_return_val_if_fail(pkg_filename != nullptr, nullptr);
int len = strlen(pkg_filename); int len = strlen(pkg_filename);
if (len < 4) if (len < 4)
{ {
return nullptr; return nullptr;
} }
if (pkg_filename[len - 4] == '.') if (pkg_filename[len - 4] == '.')
{ {
pkg_tokens = static_cast<char **> (g_malloc_n (6, sizeof (char *))); pkg_tokens = static_cast<char **>(g_malloc_n (6, sizeof (char *)));
/* Full name without extension */ /* Full name without extension */
len -= 4; len -= 4;
pkg_full_name = g_strndup (pkg_filename, len); pkg_full_name = g_strndup(pkg_filename, len);
pkg_tokens[3] = g_strdup (pkg_full_name); pkg_tokens[3] = g_strdup(pkg_full_name);
/* The last 3 characters should be the file extension */ /* The last 3 characters should be the file extension */
pkg_tokens[4] = g_strdup (pkg_filename + len + 1); pkg_tokens[4] = g_strdup(pkg_filename + len + 1);
pkg_tokens[5] = nullptr; pkg_tokens[5] = nullptr;
} }
else else
{ {
pkg_tokens = static_cast<char **> (g_malloc_n (4, sizeof (char *))); pkg_tokens = static_cast<char **>(g_malloc_n (4, sizeof (char *)));
pkg_full_name = g_strdup (pkg_filename); pkg_full_name = g_strdup(pkg_filename);
pkg_tokens[3] = nullptr; pkg_tokens[3] = nullptr;
} }
/* Reverse all of the bytes in the package filename to get the name, version and the architecture */ /* Reverse all of the bytes in the package filename to get the name, version and the architecture */
g_strreverse (pkg_full_name); g_strreverse (pkg_full_name);
char **reversed_tokens = g_strsplit (pkg_full_name, "-", 4); char **reversed_tokens = g_strsplit(pkg_full_name, "-", 4);
pkg_tokens[0] = g_strreverse (reversed_tokens[3]); /* Name */ pkg_tokens[0] = g_strreverse(reversed_tokens[3]); /* Name */
pkg_tokens[1] = g_strreverse (reversed_tokens[2]); /* Version */ pkg_tokens[1] = g_strreverse(reversed_tokens[2]); /* Version */
pkg_tokens[2] = g_strreverse (reversed_tokens[1]); /* Architecture */ pkg_tokens[2] = g_strreverse(reversed_tokens[1]); /* Architecture */
g_free (reversed_tokens[0]); /* Build number */ g_free(reversed_tokens[0]); /* Build number */
g_free (reversed_tokens); g_free(reversed_tokens);
g_free (pkg_full_name); g_free(pkg_full_name);
return pkg_tokens; return pkg_tokens;
} }
/** /**
* katja::is_installed: * katja::is_installed:
* Checks if a package is already installed in the system. * Checks if a package is already installed in the system.
* *
* Params: * @pkg_fullname: Package name should be looked for.
* pkg_fullname = Package name should be looked for.
* *
* Returns: Package installation information. * Returns: Package installation information.
**/ **/
Info Info is_installed(const char *pkg_fullname)
is_installed (const char *pkg_fullname)
{ {
GFileEnumerator *pkg_metadata_enumerator; GFileEnumerator *pkg_metadata_enumerator;
GFileInfo *pkg_metadata_file_info; GFileInfo *pkg_metadata_file_info;
GFile *pkg_metadata_dir; GFile *pkg_metadata_dir;
Info ret = Info::installing; Info ret = Info::installing;
const char *it; const char *it;
std::uint8_t dashes = 0; std::uint8_t dashes = 0;
ptrdiff_t pkg_name; ptrdiff_t pkg_name;
g_return_val_if_fail(pkg_fullname != nullptr, Info::unknown); g_return_val_if_fail(pkg_fullname != nullptr, Info::unknown);
// We want to find the package name without version for the package we're // We want to find the package name without version for the package we're
// looking for. // looking for.
@@ -162,75 +158,73 @@ is_installed (const char *pkg_fullname)
++dashes; ++dashes;
} }
} }
if (dashes < 2) if (dashes < 2)
{ {
return Info::unknown; return Info::unknown;
} }
pkg_name = it - pkg_fullname; pkg_name = it - pkg_fullname;
// Read the package metadata directory and comprare all installed packages // Read the package metadata directory and comprare all installed packages
// with ones in the cache. // with ones in the cache.
pkg_metadata_dir = g_file_new_for_path("/var/log/packages"); pkg_metadata_dir = g_file_new_for_path("/var/log/packages");
if (!(pkg_metadata_enumerator = g_file_enumerate_children(pkg_metadata_dir, if (!(pkg_metadata_enumerator = g_file_enumerate_children(pkg_metadata_dir,
"standard::name", "standard::name",
G_FILE_QUERY_INFO_NONE, G_FILE_QUERY_INFO_NONE,
nullptr, nullptr,
nullptr))) nullptr)))
{ {
g_object_unref(pkg_metadata_dir); g_object_unref(pkg_metadata_dir);
return Info::unknown; return Info::unknown;
} }
while ((pkg_metadata_file_info = g_file_enumerator_next_file(pkg_metadata_enumerator, nullptr, nullptr))) while ((pkg_metadata_file_info = g_file_enumerator_next_file(pkg_metadata_enumerator, nullptr, nullptr)))
{ {
const char *dir = g_file_info_get_name(pkg_metadata_file_info); const char *dir = g_file_info_get_name(pkg_metadata_file_info);
dashes = 0; dashes = 0;
if (strcmp(dir, pkg_fullname) == 0) if (strcmp(dir, pkg_fullname) == 0)
{ {
ret = Info::installed; ret = Info::installed;
} }
else else
{ {
for (it = dir + strlen(dir); it != dir; --it) for (it = dir + strlen(dir); it != dir; --it)
{ {
if (*it == '-') if (*it == '-')
{ {
if (dashes == 2) if (dashes == 2)
{ {
break; break;
} }
++dashes; ++dashes;
} }
} }
if (pkg_name == (it - dir) && strncmp(pkg_fullname, dir, pkg_name) == 0) if (pkg_name == (it - dir) && strncmp(pkg_fullname, dir, pkg_name) == 0)
{ {
ret = Info::updating; ret = Info::updating;
} }
}
g_object_unref(pkg_metadata_file_info);
} if (ret != Info::installing) /* If installed */
g_object_unref(pkg_metadata_file_info); {
break;
}
}
g_object_unref(pkg_metadata_enumerator);
g_object_unref(pkg_metadata_dir);
if (ret != Info::installing) /* If installed */ return ret;
{
break;
}
}
g_object_unref(pkg_metadata_enumerator);
g_object_unref(pkg_metadata_dir);
return ret;
} }
/** /**
* katja::cmp_repo: * katja::cmp_repo:
**/ **/
int int cmp_repo(const void *a, const void *b)
cmp_repo (const void *a, const void *b)
{ {
auto repo = static_cast<const Pkgtools *> (a); auto repo = static_cast<const Pkgtools *> (a);
return g_strcmp0 (repo->get_name (), (char *) b); return g_strcmp0(repo->get_name(), (char *) b);
} }
} }
+9 -7
View File
@@ -11,8 +11,8 @@ namespace katja
{ {
struct JobData struct JobData
{ {
sqlite3 *db; sqlite3 *db;
CURL *curl; CURL *curl;
}; };
enum class Info enum class Info
@@ -24,15 +24,17 @@ enum class Info
// A different version is installed. // A different version is installed.
updating, updating,
// Available, but not installed. // Available, but not installed.
installing installing,
// Available.
available
}; };
CURLcode get_file (CURL **curl, char *source_url, char *dest); CURLcode get_file(CURL **curl, char *source_url, char *dest);
char **split_package_name (const char *pkg_filename); char **split_package_name(const char *pkg_filename);
Info is_installed (const char *pkg_fullname); Info is_installed(const char *pkg_fullname);
int cmp_repo (const void *a, const void *b); int cmp_repo(const void *a, const void *b);
} }