Add a configuration header
Test / build (push) Successful in 43s

This commit is contained in:
2026-05-02 12:59:59 +02:00
parent 12dc26051c
commit d84e192ae9
9 changed files with 43 additions and 40 deletions
+4 -1
View File
@@ -3,7 +3,7 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0) 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
@@ -11,6 +11,9 @@ target_sources(backend
PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc dl.cc PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc dl.cc
) )
configure_file(config.h.in ${CMAKE_BINARY_DIR}/generated/config.h)
include_directories(${CMAKE_BINARY_DIR}/generated/)
target_link_libraries(backend PkgConfig::deps) target_link_libraries(backend PkgConfig::deps)
# curl_dep = meson.get_compiler('c').find_library('curl') # curl_dep = meson.get_compiler('c').find_library('curl')
# bzip2_dep = dependency('bzip2') # bzip2_dep = dependency('bzip2')
+9
View File
@@ -0,0 +1,9 @@
#ifndef CONFIG_H
#define CONFIG_H
#define G_LOG_DOMAIN "Katja"
#define LOCALSTATEDIR "@CMAKE_INSTALL_LOCALSTATEDIR@"
#define LIBDIR "@CMAKE_INSTALL_LIBDIR@"
#define SYSCONFDIR "@CMAKE_INSTALL_SYSCONFDIR@"
#endif // CONFIG_H
+1
View File
@@ -5,6 +5,7 @@
*/ */
#include <sqlite3.h> #include <sqlite3.h>
#include <stdlib.h> #include <stdlib.h>
#include <gio/gio.h>
#include "dl.h" #include "dl.h"
#include "utils.h" #include "utils.h"
+23 -36
View File
@@ -3,14 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
#include "config.h"
#include <dirent.h> #include <dirent.h>
#include <glib/gstdio.h> #include <gio/gio.h>
#include <cstdint> #include <cstdint>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <iostream>
#include <zlib.h> #include <zlib.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <pk-backend.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "job.h" #include "job.h"
#include "dl.h" #include "dl.h"
@@ -18,6 +18,8 @@
#include "slackpkg.h" #include "slackpkg.h"
#include "utils.h" #include "utils.h"
using namespace katja;
static GSList *repos = nullptr; static GSList *repos = nullptr;
void pk_backend_initialize(GKeyFile *conf) void pk_backend_initialize(GKeyFile *conf)
@@ -150,10 +152,7 @@ void pk_backend_start_job(PkBackendJob *job)
} }
else else
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, std::cerr << db_filename << ": " << sqlite3_errmsg(job_data->db) << std::endl;
"%s: %s",
db_filename,
sqlite3_errmsg(job_data->db));
goto out; goto out;
} }
@@ -220,10 +219,8 @@ pk_backend_search_thread (PkBackendJob *job, GVariant *params, void *user_data)
} }
else else
{ {
pk_backend_job_error_code (job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
"%s", sqlite3_errmsg (job_data->db));
} }
sqlite3_free (query); sqlite3_free (query);
g_free (search); g_free (search);
} }
@@ -251,8 +248,6 @@ void pk_backend_search_files(PkBackendJob *job, char **values)
Info ret; Info ret;
auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job)); auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job));
pk_backend_job_set_percentage(job, 0);
search = g_strjoinv("%", values); search = g_strjoinv("%", values);
query = sqlite3_mprintf("SELECT (p.name || ';' || p.ver || ';' || p.arch || ';' || r.repo), p.summary, " query = sqlite3_mprintf("SELECT (p.name || ';' || p.ver || ';' || p.arch || ';' || r.repo), p.summary, "
@@ -282,12 +277,10 @@ void pk_backend_search_files(PkBackendJob *job, char **values)
} }
else else
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
} }
sqlite3_free(query); sqlite3_free(query);
g_free(search); g_free(search);
pk_backend_job_set_percentage(job, 100);
} }
void pk_backend_get_details(PkBackendJob *job, char **package_ids) void pk_backend_get_details(PkBackendJob *job, char **package_ids)
@@ -308,7 +301,7 @@ void pk_backend_get_details(PkBackendJob *job, char **package_ids)
-1, -1,
&stmt, &stmt,
nullptr) != SQLITE_OK)) { nullptr) != SQLITE_OK)) {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
goto out; goto out;
} }
@@ -329,7 +322,7 @@ void pk_backend_get_details(PkBackendJob *job, char **package_ids)
&err); &err);
if (err) if (err)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_UNKNOWN, "%s", err->message); std::cerr << err->message << std::endl;
g_error_free(err); g_error_free(err);
goto out; goto out;
} }
@@ -377,8 +370,6 @@ void pk_backend_resolve(PkBackendJob *job, char **packages)
PkInfoEnum ret; PkInfoEnum ret;
auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job)); auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job));
pk_backend_job_set_percentage(job, 0);
if ((sqlite3_prepare_v2(job_data->db, if ((sqlite3_prepare_v2(job_data->db,
"SELECT (p1.name || ';' || p1.ver || ';' || p1.arch || ';' || r.repo), p1.summary, " "SELECT (p1.name || ';' || p1.ver || ';' || p1.arch || ';' || r.repo), p1.summary, "
"p1.full_name FROM pkglist AS p1 NATURAL JOIN repos AS r " "p1.full_name FROM pkglist AS p1 NATURAL JOIN repos AS r "
@@ -412,11 +403,11 @@ void pk_backend_resolve(PkBackendJob *job, char **packages)
sqlite3_reset(stmt); sqlite3_reset(stmt);
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} else {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db));
} }
else
pk_backend_job_set_percentage(job, 100); {
std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
}
} }
void pk_backend_download_packages(PkBackendJob *job, char **package_ids, const char *directory) void pk_backend_download_packages(PkBackendJob *job, char **package_ids, const char *directory)
@@ -433,7 +424,7 @@ void pk_backend_download_packages(PkBackendJob *job, char **package_ids, const c
&stmt, &stmt,
nullptr) != SQLITE_OK)) nullptr) != SQLITE_OK))
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
goto out; goto out;
} }
@@ -496,7 +487,7 @@ void pk_backend_install_packages(PkBackendJob *job, char **package_ids)
&collection_stmt, &collection_stmt,
nullptr) != SQLITE_OK)) nullptr) != SQLITE_OK))
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
goto out; goto out;
} }
@@ -613,7 +604,7 @@ void pk_backend_remove_packages(PkBackendJob *job, char **package_ids)
if (err) if (err)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE, "%s", err->message); std::cerr << err->message << std::endl;
g_error_free(err); g_error_free(err);
return; return;
@@ -643,7 +634,7 @@ void pk_backend_get_updates(PkBackendJob *job)
&stmt, &stmt,
nullptr) != SQLITE_OK)) nullptr) != SQLITE_OK))
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_CANNOT_GET_FILELIST, "%s", sqlite3_errmsg(job_data->db)); std::cerr << sqlite3_errmsg(job_data->db) << std::endl;
goto out; goto out;
} }
@@ -656,7 +647,7 @@ void pk_backend_get_updates(PkBackendJob *job)
g_object_unref(pkg_metadata_dir); g_object_unref(pkg_metadata_dir);
if (err) if (err)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, "/var/log/packages: %s", err->message); std::cerr << "/var/log/packages: " << err->message << std::endl;
g_error_free(err); g_error_free(err);
goto out; goto out;
} }
@@ -792,7 +783,7 @@ void pk_backend_refresh_cache(PkBackendJob *job, bool force)
tmp_dir_name = g_dir_make_tmp("PackageKit.XXXXXX", &err); tmp_dir_name = g_dir_make_tmp("PackageKit.XXXXXX", &err);
if (!tmp_dir_name) if (!tmp_dir_name)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_INTERNAL_ERROR, "%s", err->message); std::cerr << err->message << std::endl;
g_error_free(err); g_error_free(err);
return; return;
} }
@@ -805,7 +796,7 @@ void pk_backend_refresh_cache(PkBackendJob *job, bool force)
file_info = g_file_query_info(db_file, "time::modified-usec", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, &err); file_info = g_file_query_info(db_file, "time::modified-usec", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, nullptr, &err);
if (err) if (err)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, "%s: %s", path, err->message); std::cerr << path << ": " << err->message;
g_error_free(err); g_error_free(err);
goto out; goto out;
} }
@@ -816,11 +807,7 @@ void pk_backend_refresh_cache(PkBackendJob *job, bool force)
nullptr); nullptr);
if ((ret != SQLITE_OK) || ((ret = sqlite3_step(stmt)) != SQLITE_ROW)) if ((ret != SQLITE_OK) || ((ret = sqlite3_step(stmt)) != SQLITE_ROW))
{ {
pk_backend_job_error_code(job, std::cerr << path << ": " << sqlite3_errstr(ret) << std::endl;
PK_ERROR_ENUM_NO_CACHE,
"%s: %s",
path,
sqlite3_errstr(ret));
goto out; goto out;
} }
if ((std::uint32_t) sqlite3_column_int(stmt, 0) > g_file_info_get_attribute_uint32(file_info, "time::modified-usec")) if ((std::uint32_t) sqlite3_column_int(stmt, 0) > g_file_info_get_attribute_uint32(file_info, "time::modified-usec"))
@@ -832,7 +819,7 @@ void pk_backend_refresh_cache(PkBackendJob *job, bool force)
{ {
if (sqlite3_exec(job_data->db, "DELETE FROM repos", nullptr, 0, &db_err) != SQLITE_OK) if (sqlite3_exec(job_data->db, "DELETE FROM repos", nullptr, 0, &db_err) != SQLITE_OK)
{ {
pk_backend_job_error_code(job, PK_ERROR_ENUM_INTERNAL_ERROR, "%s", db_err); std::cerr << db_err << std::endl;
sqlite3_free(db_err); sqlite3_free(db_err);
goto out; goto out;
} }
+1 -1
View File
@@ -5,7 +5,7 @@
*/ */
#pragma once #pragma once
using namespace katja; #include <glib/gstdio.h>
void pk_backend_initialize(GKeyFile *conf); void pk_backend_initialize(GKeyFile *conf);
void pk_backend_destroy(); void pk_backend_destroy();
+1
View File
@@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
#include "config.h"
#include <curl/curl.h> #include <curl/curl.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "pkgtools.h" #include "pkgtools.h"
+1
View File
@@ -2,6 +2,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <gio/gio.h>
#include "slackpkg.h" #include "slackpkg.h"
#include "utils.h" #include "utils.h"
+1
View File
@@ -6,6 +6,7 @@
#include <cstdint> #include <cstdint>
#include <sqlite3.h> #include <sqlite3.h>
#include <string.h> #include <string.h>
#include <gio/gio.h>
#include "utils.h" #include "utils.h"
#include "pkgtools.h" #include "pkgtools.h"
+2 -2
View File
@@ -22,9 +22,9 @@ enum class Info
// Installed in the same version. // Installed in the same version.
installed, installed,
// A different version is installed. // A different version is installed.
updating updating,
// Available, but not installed. // Available, but not installed.
installing, installing
}; };
CURLcode get_file (CURL **curl, char *source_url, char *dest); CURLcode get_file (CURL **curl, char *source_url, char *dest);