]> git.ipfire.org Git - pakfire.git/commitdiff
ctx: Move the OFFLINE flag into the context
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Oct 2023 17:19:09 +0000 (17:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Oct 2023 17:19:09 +0000 (17:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/cli/pakfire.c
src/libpakfire/ctx.c
src/libpakfire/downloader.c
src/libpakfire/include/pakfire/ctx.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/repo.c

index 4803fff38104562e83baed8826d4225a170a57fd..0ada88b21003a93d7d5565c491b6e8a7f87ad8b9 100644 (file)
@@ -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
index 327be48fd12c710247676711ae7bb3963c885993..cb499ce1369ccfb9c67c1237316f7e576ebf3d4f 100644 (file)
@@ -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:
index b1aff246e396a0e5558cf8ddb42c7680f3dbffb8..58c9c41ab42e00321bc32c88dc9606b69b75b187 100644 (file)
@@ -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) {
index 5daaac568fddf8a2e3be05c0315ad93ced6e076c..2fb6de8f9a76357b37b1ea025902927d5df3626f 100644 (file)
@@ -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));
index 0ea96bfcf9bb92e251b8cf900d906c3b5403f5ff..a4755db84edda89f10833ad10129fd7e55878ed4 100644 (file)
@@ -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);
index 50ab5db7ba82fe22e0ae4b228ac18050ea745e32..48b9243be0dbfaecdb9fb855b0ed7cf5fd908e29 100644 (file)
@@ -41,7 +41,6 @@ struct pakfire;
 
 enum pakfire_flags {
        PAKFIRE_FLAGS_BUILD             = (1 << 0),
-       PAKFIRE_FLAGS_OFFLINE                   = (1 << 1),
 };
 
 // Callbacks
index c48ce2cd4297a150cf668f4b77752fdbd6404051..6727e8354d19675edb21f429cd1ed3a5b08538b9 100644 (file)
@@ -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;
index 43189287d20e37e469db1ff05aa994eb1fd9eab9..73ee11e59f1705137b6bf0c5b0ed3d0832267b75 100644 (file)
@@ -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