From: Michael Tremer Date: Mon, 16 Oct 2023 17:19:09 +0000 (+0000) Subject: ctx: Move the OFFLINE flag into the context X-Git-Tag: 0.9.30~1480 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d11380ddd0f39a7e531be990a3fdc5ce8bdda558;p=people%2Fms%2Fpakfire.git ctx: Move the OFFLINE flag into the context Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 4803fff38..0ada88b21 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -61,20 +61,18 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { "path", "arch", "logger", - "offline", "conf", NULL, }; const char* path = NULL; const char* arch = NULL; PyObject* conf = Py_None; - int offline = 0; int r = 1; FILE* fconf = NULL; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzpO", kwlist, - &path, &arch, &offline, &conf)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzO", kwlist, + &path, &arch, &conf)) goto ERROR; // Map the configuration @@ -86,10 +84,6 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { int flags = 0; - // Enable offline mode - if (offline) - flags |= PAKFIRE_FLAGS_OFFLINE; - Py_BEGIN_ALLOW_THREADS // Create a new Pakfire instance diff --git a/src/cli/pakfire.c b/src/cli/pakfire.c index 327be48fd..cb499ce13 100644 --- a/src/cli/pakfire.c +++ b/src/cli/pakfire.c @@ -101,7 +101,7 @@ static error_t parse(int key, char* arg, void* data) { break; case OPT_OFFLINE: - config->flags |= PAKFIRE_FLAGS_OFFLINE; + pakfire_ctx_set_flag(config->ctx, PAKFIRE_CTX_OFFLINE); break; case OPT_ROOT: diff --git a/src/libpakfire/ctx.c b/src/libpakfire/ctx.c index b1aff246e..58c9c41ab 100644 --- a/src/libpakfire/ctx.c +++ b/src/libpakfire/ctx.c @@ -34,6 +34,9 @@ struct pakfire_ctx { // Reference counter int nrefs; + // Flags + int flags; + // Config struct pakfire_config* config; @@ -197,6 +200,18 @@ PAKFIRE_EXPORT struct pakfire_ctx* pakfire_ctx_unref(struct pakfire_ctx* ctx) { return NULL; } +// Flags + +PAKFIRE_EXPORT int pakfire_ctx_has_flag(struct pakfire_ctx* ctx, int flag) { + return ctx->flags & flag; +} + +PAKFIRE_EXPORT int pakfire_ctx_set_flag(struct pakfire_ctx* ctx, int flag) { + ctx->flags |= flag; + + return 0; +} + // Config struct pakfire_config* pakfire_ctx_get_config(struct pakfire_ctx* ctx) { diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index 5daaac568..2fb6de8f9 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -197,14 +197,11 @@ int pakfire_downloader_create( struct pakfire_downloader* d = NULL; int r; -#warning The OFFLINE flag must be moved into the context -#if 0 - // Fail if pakfire is running in offline mode - if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_OFFLINE)) { - ERROR(pakfire, "Cannot initialize downloader in offline mode\n"); - return -ENOTSUP; + // Fail if the context is flagged as offline + if (pakfire_ctx_has_flag(ctx, PAKFIRE_CTX_OFFLINE)) { + CTX_ERROR(ctx, "Cannot initialize downloader in offline mode\n"); + return -EPERM; } -#endif // Allocate a new object d = calloc(1, sizeof(*d)); diff --git a/src/libpakfire/include/pakfire/ctx.h b/src/libpakfire/include/pakfire/ctx.h index 0ea96bfcf..a4755db84 100644 --- a/src/libpakfire/include/pakfire/ctx.h +++ b/src/libpakfire/include/pakfire/ctx.h @@ -34,6 +34,15 @@ int pakfire_ctx_create(struct pakfire_ctx** ctx, const char* path); struct pakfire_ctx* pakfire_ctx_ref(struct pakfire_ctx* ctx); struct pakfire_ctx* pakfire_ctx_unref(struct pakfire_ctx* ctx); +// Flags + +enum pakfire_ctx_flags { + PAKFIRE_CTX_OFFLINE = (1 << 0), +}; + +int pakfire_ctx_has_flag(struct pakfire_ctx* ctx, int flag); +int pakfire_ctx_set_flag(struct pakfire_ctx* ctx, int flag); + // Config struct pakfire_config* pakfire_ctx_get_config(struct pakfire_ctx* ctx); diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 50ab5db7b..48b9243be 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -41,7 +41,6 @@ struct pakfire; enum pakfire_flags { PAKFIRE_FLAGS_BUILD = (1 << 0), - PAKFIRE_FLAGS_OFFLINE = (1 << 1), }; // Callbacks diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index c48ce2cd4..6727e8354 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -30,6 +30,8 @@ global: pakfire_ctx_set_confirm_callback; pakfire_ctx_set_progress_callback; pakfire_ctx_set_pick_solution_callback; + pakfire_ctx_has_flag; + pakfire_ctx_set_flag; # pakfire pakfire_check; diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 43189287d..73ee11e59 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -561,7 +561,7 @@ static int pakfire_repo_read_metadata(struct pakfire_repo* repo, const char* pat goto ERROR; // Download the database - if (!pakfire_repo_is_local(repo) && !pakfire_has_flag(repo->pakfire, PAKFIRE_FLAGS_OFFLINE)) { + if (!pakfire_repo_is_local(repo) && !pakfire_ctx_has_flag(repo->ctx, PAKFIRE_CTX_OFFLINE)) { r = pakfire_repo_download_database(repo, filename, database_path); if (r) goto ERROR; @@ -590,7 +590,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int return 0; // Do nothing if running in offline mode - if (pakfire_has_flag(repo->pakfire, PAKFIRE_FLAGS_OFFLINE)) + if (pakfire_ctx_has_flag(repo->ctx, PAKFIRE_CTX_OFFLINE)) return 0; // This repository does not have a mirrorlist @@ -657,7 +657,7 @@ static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* return 0; // Do nothing if running in offline mode - if (pakfire_has_flag(repo->pakfire, PAKFIRE_FLAGS_OFFLINE)) + if (pakfire_ctx_has_flag(repo->ctx, PAKFIRE_CTX_OFFLINE)) return 0; // Fetch refresh interval