@@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 4.0.0)
|
||||
project(Katja LANGUAGES CXX)
|
||||
|
||||
include(CTest)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
option(KATJA_BUILD_CLI "Build command line interface" ON)
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0)
|
||||
|
||||
add_library(backend)
|
||||
target_sources(backend
|
||||
INTERFACE job.h utils.h pkgtools.h slackpkg.h dl.h
|
||||
PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc dl.cc
|
||||
INTERFACE job.h utils.h pkgtools.h slackpkg.h
|
||||
PRIVATE job.cc utils.cc pkgtools.cc slackpkg.cc
|
||||
)
|
||||
|
||||
configure_file(config.h.in ${CMAKE_BINARY_DIR}/generated/config.h)
|
||||
|
||||
-293
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
+6
-8
@@ -6,16 +6,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
#include "utils.h"
|
||||
|
||||
void pk_backend_initialize(GKeyFile *conf);
|
||||
void pk_backend_destroy();
|
||||
|
||||
void pk_backend_start_job(PkBackendJob *job);
|
||||
void pk_backend_stop_job(PkBackendJob *job);
|
||||
katja::JobData *pk_backend_start_job();
|
||||
void pk_backend_stop_job(katja::JobData *job_data)
|
||||
|
||||
void pk_backend_search_names(PkBackendJob *job, char **values);
|
||||
void pk_backend_search_details(PkBackendJob *job, char **values);
|
||||
void pk_backend_search_groups(PkBackendJob *job, char **values);
|
||||
void pk_backend_search_thread(PkBackendJob *job, GVariant *params, const char *user_data);
|
||||
void pk_backend_search_files(PkBackendJob *job, char **values);
|
||||
|
||||
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_get_updates(PkBackendJob *job);
|
||||
void pk_backend_update_packages(PkBackendJob *job, char **package_ids);
|
||||
void pk_backend_refresh_cache(PkBackendJob *job, bool force);
|
||||
void pk_backend_get_update_detail(PkBackendJob *job, char **package_ids);
|
||||
void pk_backend_update_packages(katja::JobData *job_data, char **package_ids);
|
||||
void pk_backend_refresh_cache(katja::JobData *job, bool force);
|
||||
|
||||
+74
-90
@@ -12,7 +12,7 @@ namespace katja
|
||||
{
|
||||
/**
|
||||
* katja::Pkgtools::download:
|
||||
* @job: A #PkBackendJob.
|
||||
* @job_data: A #JobData.
|
||||
* @dest_dir_name: Destination directory.
|
||||
* @pkg_name: Package name.
|
||||
*
|
||||
@@ -20,57 +20,47 @@ namespace katja
|
||||
*
|
||||
* Returns: %TRUE on success, %FALSE otherwise.
|
||||
**/
|
||||
bool
|
||||
Pkgtools::download (JobData *job_data,
|
||||
char *dest_dir_name, char *pkg_name) noexcept
|
||||
bool Pkgtools::download(JobData *job_data, char *dest_dir_name, char *pkg_name) noexcept
|
||||
{
|
||||
char *dest_filename, *source_url;
|
||||
bool ret = false;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
CURL *curl = nullptr;
|
||||
char *dest_filename, *source_url;
|
||||
bool ret = false;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
CURL *curl = nullptr;
|
||||
|
||||
if ((sqlite3_prepare_v2(job_data->db,
|
||||
"SELECT location, (full_name || '.' || ext) FROM pkglist "
|
||||
"WHERE name LIKE @name AND repo_order = @repo_order",
|
||||
-1,
|
||||
&statement,
|
||||
nullptr) != SQLITE_OK))
|
||||
return false;
|
||||
if ((sqlite3_prepare_v2(job_data->db,
|
||||
"SELECT location, (full_name || '.' || ext) FROM pkglist "
|
||||
"WHERE name LIKE @name AND repo_order = @repo_order",
|
||||
-1,
|
||||
&statement,
|
||||
nullptr) != SQLITE_OK))
|
||||
{
|
||||
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);
|
||||
sqlite3_bind_int(statement, 2, this->get_order ());
|
||||
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->get_mirror(),
|
||||
sqlite3_column_text(statement, 0),
|
||||
"/",
|
||||
sqlite3_column_text(statement, 1),
|
||||
nullptr);
|
||||
|
||||
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->get_mirror (),
|
||||
sqlite3_column_text(statement, 0),
|
||||
"/",
|
||||
sqlite3_column_text(statement, 1),
|
||||
nullptr);
|
||||
ret = g_file_test(dest_filename, G_FILE_TEST_EXISTS)
|
||||
|| get_file(&curl, source_url, dest_filename) == CURLE_OK;
|
||||
|
||||
if (!g_file_test(dest_filename, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
if (get_file(&curl, source_url, dest_filename) == CURLE_OK)
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
if (curl)
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
g_free(source_url);
|
||||
g_free(dest_filename);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
|
||||
if (curl)
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
g_free(source_url);
|
||||
g_free(dest_filename);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,43 +70,42 @@ Pkgtools::download (JobData *job_data,
|
||||
*
|
||||
* Install a package.
|
||||
**/
|
||||
void
|
||||
Pkgtools::install (JobData *job_data, char *pkg_name) noexcept
|
||||
void Pkgtools::install(JobData *job_data, char *pkg_name) noexcept
|
||||
{
|
||||
char *pkg_filename, *cmd_line;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
char *pkg_filename, *cmd_line;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
|
||||
if ((sqlite3_prepare_v2(job_data->db,
|
||||
"SELECT (full_name || '.' || ext) FROM pkglist "
|
||||
"WHERE name LIKE @name AND repo_order = @repo_order",
|
||||
-1,
|
||||
&statement,
|
||||
nullptr) != SQLITE_OK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((sqlite3_prepare_v2(job_data->db,
|
||||
"SELECT (full_name || '.' || ext) FROM pkglist "
|
||||
"WHERE name LIKE @name AND repo_order = @repo_order",
|
||||
-1,
|
||||
&statement,
|
||||
nullptr) != SQLITE_OK))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
sqlite3_bind_int(statement, 2, this->get_order());
|
||||
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
pkg_filename = g_build_filename(LOCALSTATEDIR,
|
||||
"cache",
|
||||
"PackageKit",
|
||||
"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);
|
||||
if (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
pkg_filename = g_build_filename(LOCALSTATEDIR,
|
||||
"cache",
|
||||
"PackageKit",
|
||||
"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);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
g_free(pkg_filename);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
|
||||
Pkgtools::~Pkgtools () noexcept
|
||||
Pkgtools::~Pkgtools() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
@@ -127,10 +116,9 @@ Pkgtools::~Pkgtools () noexcept
|
||||
*
|
||||
* Returns: Repository name.
|
||||
**/
|
||||
const char *
|
||||
Pkgtools::get_name () const noexcept
|
||||
const char *Pkgtools::get_name() const noexcept
|
||||
{
|
||||
return this->name;
|
||||
return this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,10 +128,9 @@ Pkgtools::get_name () const noexcept
|
||||
*
|
||||
* Returns: Repository mirror.
|
||||
**/
|
||||
const char *
|
||||
Pkgtools::get_mirror () const noexcept
|
||||
const char *Pkgtools::get_mirror() const noexcept
|
||||
{
|
||||
return this->mirror;
|
||||
return this->mirror;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,10 +140,9 @@ Pkgtools::get_mirror () const noexcept
|
||||
*
|
||||
* Returns: Repository order.
|
||||
**/
|
||||
guint8
|
||||
Pkgtools::get_order () const noexcept
|
||||
guint8 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.
|
||||
**/
|
||||
bool
|
||||
Pkgtools::is_blacklisted (const char *pkg) const noexcept
|
||||
bool Pkgtools::is_blacklisted(const char *pkg) const noexcept
|
||||
{
|
||||
return this->blacklist
|
||||
&& g_regex_match (this->blacklist,
|
||||
pkg, static_cast<GRegexMatchFlags> (0), nullptr);
|
||||
return this->blacklist
|
||||
&& g_regex_match (this->blacklist, pkg, static_cast<GRegexMatchFlags>(0), nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-15
@@ -14,26 +14,23 @@ namespace katja
|
||||
class Pkgtools
|
||||
{
|
||||
public:
|
||||
const char *get_name () const noexcept;
|
||||
const char *get_mirror () const noexcept;
|
||||
std::uint8_t get_order () const noexcept;
|
||||
bool is_blacklisted (const char *pkg) const noexcept;
|
||||
const char *get_name() const noexcept;
|
||||
const char *get_mirror() const noexcept;
|
||||
std::uint8_t get_order() const noexcept;
|
||||
bool is_blacklisted(const char *pkg) const noexcept;
|
||||
|
||||
virtual ~Pkgtools () noexcept;
|
||||
virtual ~Pkgtools() noexcept;
|
||||
|
||||
bool download (JobData *job_data,
|
||||
char *dest_dir_name, char *pkg_name) noexcept;
|
||||
void install (JobData *job_data, char *pkg_name) noexcept;
|
||||
bool download(JobData *job_data, char *dest_dir_name, char *pkg_name) noexcept;
|
||||
void install(JobData *job_data, char *pkg_name) noexcept;
|
||||
|
||||
virtual GSList *collect_cache_info (const char *tmpl) noexcept = 0;
|
||||
virtual void generate_cache (JobData *job_data,
|
||||
const char *tmpl) noexcept = 0;
|
||||
virtual GSList *collect_cache_info (const char *tmpl) noexcept = 0;
|
||||
virtual void generate_cache(JobData *job_data, const char *tmpl) noexcept = 0;
|
||||
|
||||
protected:
|
||||
char *name = nullptr;
|
||||
char *mirror = nullptr;
|
||||
char *name = nullptr;
|
||||
char *mirror = nullptr;
|
||||
std::uint8_t order;
|
||||
GRegex *blacklist = nullptr;
|
||||
GRegex *blacklist = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+16
-29
@@ -12,15 +12,14 @@ GHashTable *Slackpkg::cat_map = nullptr;
|
||||
|
||||
/*
|
||||
* katja::Slackpkg::manifest:
|
||||
* @job: a #PkBackendJob.
|
||||
* @job: a #JobData.
|
||||
* @tmpl: temporary directory.
|
||||
* @filename: manifest filename
|
||||
*
|
||||
* Parse the manifest file and save the file list in the database.
|
||||
*/
|
||||
void
|
||||
Slackpkg::manifest (PkBackendJob *job,
|
||||
const char *tmpl, char *filename) noexcept
|
||||
Slackpkg::manifest(JobData *job_data, const char *tmpl, char *filename) noexcept
|
||||
{
|
||||
FILE *manifest;
|
||||
int err, read_len;
|
||||
@@ -32,10 +31,9 @@ Slackpkg::manifest (PkBackendJob *job,
|
||||
GRegex *pkg_expr = nullptr, *file_expr = nullptr;
|
||||
GMatchInfo *match_info;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job));
|
||||
|
||||
path = g_build_filename(tmpl,
|
||||
this->get_name (),
|
||||
this->get_name(),
|
||||
filename,
|
||||
nullptr);
|
||||
manifest = fopen(path, "rb");
|
||||
@@ -169,19 +167,19 @@ Slackpkg::collect_cache_info (const char *tmpl) noexcept
|
||||
|
||||
/* 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 ());
|
||||
repo_tmp_dir = g_file_get_child(tmp_dir, this->get_name());
|
||||
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 */
|
||||
for (char **cur_priority = this->priority; *cur_priority; cur_priority++)
|
||||
{
|
||||
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,
|
||||
"/PACKAGES.TXT",
|
||||
nullptr);
|
||||
source_dest[1] = g_build_filename(tmpl,
|
||||
this->get_name (),
|
||||
this->get_name(),
|
||||
"PACKAGES.TXT",
|
||||
nullptr);
|
||||
source_dest[2] = nullptr;
|
||||
@@ -199,12 +197,12 @@ Slackpkg::collect_cache_info (const char *tmpl) noexcept
|
||||
|
||||
/* Download file lists if available */
|
||||
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,
|
||||
"/MANIFEST.bz2",
|
||||
nullptr);
|
||||
source_dest[1] = g_strconcat(tmpl,
|
||||
"/", this->get_name (),
|
||||
"/", this->get_name(),
|
||||
"/", *cur_priority, "-MANIFEST.bz2",
|
||||
nullptr);
|
||||
source_dest[2] = nullptr;
|
||||
@@ -239,7 +237,7 @@ out:
|
||||
* Returns: List of files needed for building the cache.
|
||||
**/
|
||||
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 *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;
|
||||
|
||||
/* Check if the temporary directory for this repository exists, then the file metadata have to be generated */
|
||||
packages_txt = g_build_filename(tmpl,
|
||||
this->get_name (),
|
||||
"PACKAGES.TXT",
|
||||
nullptr);
|
||||
packages_txt = g_build_filename(tmpl, this->get_name(), "PACKAGES.TXT", nullptr);
|
||||
list_file = g_file_new_for_path(packages_txt);
|
||||
fin = g_file_read(list_file, nullptr, nullptr);
|
||||
g_object_unref(list_file);
|
||||
@@ -271,11 +266,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
|
||||
&statement,
|
||||
nullptr) == SQLITE_OK)
|
||||
{
|
||||
sqlite3_bind_text(statement,
|
||||
1,
|
||||
this->get_name (),
|
||||
-1,
|
||||
SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(statement, 1, this->get_name(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_step(statement);
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
@@ -287,12 +278,8 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
|
||||
{
|
||||
goto out;
|
||||
}
|
||||
sqlite3_bind_int(statement, 1, this->get_order ());
|
||||
sqlite3_bind_text(statement,
|
||||
2,
|
||||
this->get_name (),
|
||||
-1,
|
||||
SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(statement, 1, this->get_order());
|
||||
sqlite3_bind_text(statement, 2, this->get_name(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_step(statement);
|
||||
sqlite3_finalize(statement);
|
||||
|
||||
@@ -320,7 +307,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
|
||||
"ext = @ext, location = @location, summary = @summary, "
|
||||
"desc = @desc, compressed = @compressed, uncompressed = @uncompressed "
|
||||
"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)
|
||||
{
|
||||
goto out;
|
||||
@@ -392,7 +379,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
|
||||
{
|
||||
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 */
|
||||
{
|
||||
@@ -433,7 +420,7 @@ Slackpkg::generate_cache (JobData *job_data, const char *tmpl) noexcept
|
||||
for (char **p = this->priority; *p; p++)
|
||||
{
|
||||
filename = g_strconcat(*p, "-MANIFEST.bz2", nullptr);
|
||||
manifest (job, tmpl, filename);
|
||||
manifest(job_data, tmpl, filename);
|
||||
g_free(filename);
|
||||
}
|
||||
out:
|
||||
|
||||
+2
-3
@@ -20,15 +20,14 @@ public:
|
||||
~Slackpkg () 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:
|
||||
static GHashTable *cat_map;
|
||||
static const std::size_t max_buf_size = 8192;
|
||||
char **priority = nullptr;
|
||||
|
||||
void manifest (PkBackendJob *job,
|
||||
const char *tmpl, char *filename) noexcept;
|
||||
void manifest(JobData *job_data, const char *tmpl, char *filename) noexcept;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+135
-141
@@ -22,130 +22,126 @@ namespace katja
|
||||
*
|
||||
* Returns: CURLE_OK (zero) on success, non-zero otherwise.
|
||||
**/
|
||||
CURLcode
|
||||
get_file (CURL **curl, char *source_url, char *dest)
|
||||
CURLcode get_file(CURL **curl, char *source_url, char *dest)
|
||||
{
|
||||
char *dest_dir_name;
|
||||
FILE *fout = nullptr;
|
||||
CURLcode ret;
|
||||
glong response_code;
|
||||
char *dest_dir_name;
|
||||
FILE *fout = nullptr;
|
||||
CURLcode ret;
|
||||
glong response_code;
|
||||
|
||||
if ((*curl == nullptr) && (!(*curl = curl_easy_init())))
|
||||
{
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
}
|
||||
if ((*curl == nullptr) && (!(*curl = curl_easy_init())))
|
||||
{
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
}
|
||||
|
||||
curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(*curl, CURLOPT_URL, source_url);
|
||||
curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(*curl, CURLOPT_URL, source_url);
|
||||
|
||||
if (dest == nullptr)
|
||||
{
|
||||
curl_easy_setopt(*curl, CURLOPT_NOBODY, 1L);
|
||||
curl_easy_setopt(*curl, CURLOPT_HEADER, 1L);
|
||||
ret = curl_easy_perform(*curl);
|
||||
curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &response_code);
|
||||
if (dest == nullptr)
|
||||
{
|
||||
curl_easy_setopt(*curl, CURLOPT_NOBODY, 1L);
|
||||
curl_easy_setopt(*curl, CURLOPT_HEADER, 1L);
|
||||
ret = curl_easy_perform(*curl);
|
||||
curl_easy_getinfo(*curl, CURLINFO_RESPONSE_CODE, &response_code);
|
||||
|
||||
if (response_code != 200)
|
||||
{
|
||||
ret = CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_file_test(dest, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
dest_dir_name = dest;
|
||||
dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), nullptr);
|
||||
g_free(dest_dir_name);
|
||||
}
|
||||
if ((fout = fopen(dest, "ab")) == nullptr)
|
||||
{
|
||||
return CURLE_WRITE_ERROR;
|
||||
}
|
||||
curl_easy_setopt(*curl, CURLOPT_WRITEDATA, fout);
|
||||
ret = curl_easy_perform(*curl);
|
||||
}
|
||||
curl_easy_reset(*curl);
|
||||
if (fout != nullptr)
|
||||
{
|
||||
fclose(fout);
|
||||
}
|
||||
return ret;
|
||||
if (response_code != 200)
|
||||
{
|
||||
ret = CURLE_REMOTE_FILE_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_file_test(dest, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
dest_dir_name = dest;
|
||||
dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), nullptr);
|
||||
g_free(dest_dir_name);
|
||||
}
|
||||
if ((fout = fopen(dest, "ab")) == nullptr)
|
||||
{
|
||||
return CURLE_WRITE_ERROR;
|
||||
}
|
||||
curl_easy_setopt(*curl, CURLOPT_WRITEDATA, fout);
|
||||
ret = curl_easy_perform(*curl);
|
||||
}
|
||||
curl_easy_reset(*curl);
|
||||
if (fout != nullptr)
|
||||
{
|
||||
fclose(fout);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* katja::split_package_name:
|
||||
* Got the name of a package, without version-arch-release data.
|
||||
**/
|
||||
char **
|
||||
split_package_name (const char *pkg_filename)
|
||||
char **split_package_name(const char *pkg_filename)
|
||||
{
|
||||
char *pkg_full_name;
|
||||
char **pkg_tokens;
|
||||
char *pkg_full_name;
|
||||
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);
|
||||
if (len < 4)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
int len = strlen(pkg_filename);
|
||||
if (len < 4)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (pkg_filename[len - 4] == '.')
|
||||
{
|
||||
pkg_tokens = static_cast<char **> (g_malloc_n (6, sizeof (char *)));
|
||||
if (pkg_filename[len - 4] == '.')
|
||||
{
|
||||
pkg_tokens = static_cast<char **>(g_malloc_n (6, sizeof (char *)));
|
||||
|
||||
/* Full name without extension */
|
||||
len -= 4;
|
||||
pkg_full_name = g_strndup (pkg_filename, len);
|
||||
pkg_tokens[3] = g_strdup (pkg_full_name);
|
||||
/* Full name without extension */
|
||||
len -= 4;
|
||||
pkg_full_name = g_strndup(pkg_filename, len);
|
||||
pkg_tokens[3] = g_strdup(pkg_full_name);
|
||||
|
||||
/* The last 3 characters should be the file extension */
|
||||
pkg_tokens[4] = g_strdup (pkg_filename + len + 1);
|
||||
pkg_tokens[5] = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg_tokens = static_cast<char **> (g_malloc_n (4, sizeof (char *)));
|
||||
pkg_full_name = g_strdup (pkg_filename);
|
||||
pkg_tokens[3] = nullptr;
|
||||
}
|
||||
/* The last 3 characters should be the file extension */
|
||||
pkg_tokens[4] = g_strdup(pkg_filename + len + 1);
|
||||
pkg_tokens[5] = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg_tokens = static_cast<char **>(g_malloc_n (4, sizeof (char *)));
|
||||
pkg_full_name = g_strdup(pkg_filename);
|
||||
pkg_tokens[3] = nullptr;
|
||||
}
|
||||
|
||||
/* Reverse all of the bytes in the package filename to get the name, version and the architecture */
|
||||
g_strreverse (pkg_full_name);
|
||||
char **reversed_tokens = g_strsplit (pkg_full_name, "-", 4);
|
||||
pkg_tokens[0] = g_strreverse (reversed_tokens[3]); /* Name */
|
||||
pkg_tokens[1] = g_strreverse (reversed_tokens[2]); /* Version */
|
||||
pkg_tokens[2] = g_strreverse (reversed_tokens[1]); /* Architecture */
|
||||
/* Reverse all of the bytes in the package filename to get the name, version and the architecture */
|
||||
g_strreverse (pkg_full_name);
|
||||
char **reversed_tokens = g_strsplit(pkg_full_name, "-", 4);
|
||||
pkg_tokens[0] = g_strreverse(reversed_tokens[3]); /* Name */
|
||||
pkg_tokens[1] = g_strreverse(reversed_tokens[2]); /* Version */
|
||||
pkg_tokens[2] = g_strreverse(reversed_tokens[1]); /* Architecture */
|
||||
|
||||
g_free (reversed_tokens[0]); /* Build number */
|
||||
g_free (reversed_tokens);
|
||||
g_free (pkg_full_name);
|
||||
g_free(reversed_tokens[0]); /* Build number */
|
||||
g_free(reversed_tokens);
|
||||
g_free(pkg_full_name);
|
||||
|
||||
return pkg_tokens;
|
||||
return pkg_tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* katja::is_installed:
|
||||
* 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.
|
||||
**/
|
||||
Info
|
||||
is_installed (const char *pkg_fullname)
|
||||
Info is_installed(const char *pkg_fullname)
|
||||
{
|
||||
GFileEnumerator *pkg_metadata_enumerator;
|
||||
GFileInfo *pkg_metadata_file_info;
|
||||
GFile *pkg_metadata_dir;
|
||||
Info ret = Info::installing;
|
||||
GFileEnumerator *pkg_metadata_enumerator;
|
||||
GFileInfo *pkg_metadata_file_info;
|
||||
GFile *pkg_metadata_dir;
|
||||
Info ret = Info::installing;
|
||||
const char *it;
|
||||
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
|
||||
// looking for.
|
||||
@@ -162,75 +158,73 @@ is_installed (const char *pkg_fullname)
|
||||
++dashes;
|
||||
}
|
||||
}
|
||||
if (dashes < 2)
|
||||
{
|
||||
return Info::unknown;
|
||||
}
|
||||
if (dashes < 2)
|
||||
{
|
||||
return Info::unknown;
|
||||
}
|
||||
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.
|
||||
pkg_metadata_dir = g_file_new_for_path("/var/log/packages");
|
||||
if (!(pkg_metadata_enumerator = g_file_enumerate_children(pkg_metadata_dir,
|
||||
"standard::name",
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
nullptr,
|
||||
nullptr)))
|
||||
{
|
||||
g_object_unref(pkg_metadata_dir);
|
||||
return Info::unknown;
|
||||
}
|
||||
pkg_metadata_dir = g_file_new_for_path("/var/log/packages");
|
||||
if (!(pkg_metadata_enumerator = g_file_enumerate_children(pkg_metadata_dir,
|
||||
"standard::name",
|
||||
G_FILE_QUERY_INFO_NONE,
|
||||
nullptr,
|
||||
nullptr)))
|
||||
{
|
||||
g_object_unref(pkg_metadata_dir);
|
||||
return Info::unknown;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
dashes = 0;
|
||||
|
||||
if (strcmp(dir, pkg_fullname) == 0)
|
||||
{
|
||||
ret = Info::installed;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (it = dir + strlen(dir); it != dir; --it)
|
||||
{
|
||||
if (*it == '-')
|
||||
{
|
||||
if (dashes == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++dashes;
|
||||
}
|
||||
}
|
||||
if (pkg_name == (it - dir) && strncmp(pkg_fullname, dir, pkg_name) == 0)
|
||||
{
|
||||
ret = Info::updating;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (it = dir + strlen(dir); it != dir; --it)
|
||||
{
|
||||
if (*it == '-')
|
||||
{
|
||||
if (dashes == 2)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++dashes;
|
||||
}
|
||||
}
|
||||
if (pkg_name == (it - dir) && strncmp(pkg_fullname, dir, pkg_name) == 0)
|
||||
{
|
||||
ret = Info::updating;
|
||||
}
|
||||
}
|
||||
g_object_unref(pkg_metadata_file_info);
|
||||
|
||||
}
|
||||
g_object_unref(pkg_metadata_file_info);
|
||||
if (ret != Info::installing) /* If installed */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_object_unref(pkg_metadata_enumerator);
|
||||
g_object_unref(pkg_metadata_dir);
|
||||
|
||||
if (ret != Info::installing) /* If installed */
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_object_unref(pkg_metadata_enumerator);
|
||||
g_object_unref(pkg_metadata_dir);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* katja::cmp_repo:
|
||||
**/
|
||||
int
|
||||
cmp_repo (const void *a, const void *b)
|
||||
int 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
@@ -11,8 +11,8 @@ namespace katja
|
||||
{
|
||||
struct JobData
|
||||
{
|
||||
sqlite3 *db;
|
||||
CURL *curl;
|
||||
sqlite3 *db;
|
||||
CURL *curl;
|
||||
};
|
||||
|
||||
enum class Info
|
||||
@@ -24,15 +24,17 @@ enum class Info
|
||||
// A different version is installed.
|
||||
updating,
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user