summaryrefslogtreecommitdiff
path: root/backend/dl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'backend/dl.cc')
-rw-r--r--backend/dl.cc68
1 files changed, 36 insertions, 32 deletions
diff --git a/backend/dl.cc b/backend/dl.cc
index 5a749c1..06698c9 100644
--- a/backend/dl.cc
+++ b/backend/dl.cc
@@ -1,3 +1,8 @@
+/*
+ * 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 "dl.h"
@@ -15,27 +20,27 @@ namespace slack {
* Returns: List of files needed for building the cache.
**/
GSList *
-Dl::collect_cache_info (const gchar *tmpl) noexcept
+Dl::collect_cache_info (const char *tmpl) noexcept
{
- CURL *curl = NULL;
- GSList *file_list = NULL;
+ 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, NULL, NULL);
+ 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<gchar **> (g_malloc_n(3, sizeof(gchar *)));
+ 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",
- NULL);
- source_dest[2] = NULL;
+ nullptr);
+ source_dest[2] = nullptr;
/* Check if the remote file can be found */
- if (get_file(&curl, source_dest[0], NULL))
+ if (get_file(&curl, source_dest[0], nullptr))
{
g_strfreev(source_dest);
}
@@ -55,7 +60,7 @@ Dl::collect_cache_info (const gchar *tmpl) noexcept
/**
* slack::Dl::generate_cache:
- * @job: A #PkBackendJob.
+ * @job_data: A #JobData.
* @tmpl: temporary directory for downloading the files.
*
* Download files needed to get the information like the list of packages
@@ -64,23 +69,22 @@ Dl::collect_cache_info (const gchar *tmpl) noexcept
* Returns: List of files needed for building the cache.
**/
void
-Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
+Dl::generate_cache(JobData *job_data, const char *tmpl) noexcept
{
- gchar **line_tokens, **pkg_tokens, *line, *collection_name = NULL, *list_filename;
- gboolean skip = FALSE;
+ char **line_tokens, **pkg_tokens, *line, *collection_name = nullptr, *list_filename;
+ bool skip = false;
GFile *list_file;
GFileInputStream *fin;
- GDataInputStream *data_in = NULL;
- sqlite3_stmt *stmt = NULL;
- auto job_data = static_cast<JobData *> (pk_backend_job_get_user_data(job));
+ 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",
- NULL);
+ nullptr);
list_file = g_file_new_for_path(list_filename);
- if (!(fin = g_file_read(list_file, NULL, NULL)))
+ if (!(fin = g_file_read(list_file, nullptr, nullptr)))
{
goto out;
}
@@ -91,7 +95,7 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
"DELETE FROM repos WHERE repo LIKE @repo",
-1,
&stmt,
- NULL) == SQLITE_OK) {
+ nullptr) == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, this->get_name (), -1, SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
@@ -100,7 +104,7 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
"INSERT INTO repos (repo_order, repo) VALUES (@repo_order, @repo)",
-1,
&stmt,
- NULL) != SQLITE_OK)
+ nullptr) != SQLITE_OK)
{
goto out;
}
@@ -120,13 +124,13 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
"@desc, @compressed, @uncompressed, @cat, @repo_order, @ext)",
-1,
&stmt,
- NULL) != SQLITE_OK))
+ nullptr) != SQLITE_OK))
{
goto out;
}
- sqlite3_exec(job_data->db, "BEGIN TRANSACTION", NULL, NULL, NULL);
+ sqlite3_exec(job_data->db, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
- while ((line = g_data_input_stream_read_line(data_in, NULL, NULL, NULL)))
+ 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)
@@ -158,11 +162,11 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
}
else
{
- skip = TRUE; /* Skip other candidates for collections */
+ skip = true; /* Skip other candidates for collections */
}
if (skip)
{
- skip = FALSE;
+ skip = false;
}
else
{
@@ -186,15 +190,15 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
}
/* Create a collection entry */
- if (collection_name && g_seekable_seek(G_SEEKABLE(data_in), 0, G_SEEK_SET, NULL, NULL)
+ 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,
- NULL) == SQLITE_OK))
+ nullptr) == SQLITE_OK))
{
- while ((line = g_data_input_stream_read_line(data_in, NULL, NULL, NULL)))
+ 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)
@@ -221,7 +225,7 @@ Dl::generate_cache(PkBackendJob *job, const gchar *tmpl) noexcept
}
g_free(collection_name);
- sqlite3_exec(job_data->db, "END TRANSACTION", NULL, NULL, NULL);
+ sqlite3_exec(job_data->db, "END TRANSACTION", nullptr, nullptr, nullptr);
out:
if (data_in)
@@ -260,19 +264,19 @@ Dl::~Dl () noexcept
*
* Return value: New #slack::Dl.
**/
-Dl::Dl (const gchar *name, const gchar *mirror,
- guint8 order, const gchar *blacklist, gchar *index_file) noexcept
+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), NULL));
+ G_REGEX_OPTIMIZE, static_cast<GRegexMatchFlags> (0), nullptr));
}
else
{
- regex = NULL;
+ regex = nullptr;
}
this->name = g_strdup (name);