]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Return the error code when fetching the filelist
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 10:57:31 +0000 (10:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 10:57:31 +0000 (10:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c
src/pakfire/archive.h
src/pakfire/db.c
src/pakfire/transaction.c
src/python/archive.c
tests/libpakfire/archive.c
tests/libpakfire/makefile.c

index f6dd284fe6afd7d7785563497dd37a2c27b36a7b..fcec0ead94365e5f1ff1ee597a5260c474a21794 100644 (file)
@@ -1453,17 +1453,18 @@ static int pakfire_archive_load_filelist(struct pakfire_archive* archive) {
                PAKFIRE_EXTRACT_DRY_RUN|PAKFIRE_EXTRACT_NO_PROGRESS);
 }
 
-struct pakfire_filelist* pakfire_archive_get_filelist(struct pakfire_archive* archive) {
-       if (!archive->filelist) {
-               int r = pakfire_archive_load_filelist(archive);
-               if (r)
-                       return NULL;
-       }
+int pakfire_archive_get_filelist(struct pakfire_archive* self, struct pakfire_filelist** filelist) {
+       int r;
 
-       if (!archive->filelist)
-               return NULL;
+       // Load the filelist if we don't have one, yet
+       if (!self->filelist) {
+               r = pakfire_archive_load_filelist(self);
+               if (r < 0)
+                       return r;
+       }
 
-       return pakfire_filelist_ref(archive->filelist);
+       *filelist = pakfire_filelist_ref(self->filelist);
+       return 0;
 }
 
 int pakfire_archive_verify(struct pakfire_archive* archive, int* status) {
index 28404b8a6427157d0387e41240a9dca3002f2f66..9b91d3a0227f6c52173990fd821e1adf22fffed8 100644 (file)
@@ -51,7 +51,7 @@ const char* pakfire_archive_get_path(struct pakfire_archive* archive);
 
 unsigned int pakfire_archive_get_format(struct pakfire_archive* archive);
 
-struct pakfire_filelist* pakfire_archive_get_filelist(struct pakfire_archive* archive);
+int pakfire_archive_get_filelist(struct pakfire_archive* self, struct pakfire_filelist** filelist);
 
 int pakfire_archive_verify(struct pakfire_archive* archive, int* status);
 
index 51adffca6cb1345f0e0704a73042a72843f19e4c..52507fcdb38060ffbce84c23c6a3164050517563 100644 (file)
@@ -997,14 +997,15 @@ static int pakfire_db_bind_checksum(struct pakfire_db* db, sqlite3_stmt* stmt,
 }
 
 static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct pakfire_archive* archive) {
+       struct pakfire_filelist* filelist = NULL;
        sqlite3_stmt* stmt = NULL;
-       int r = 1;
+       int r;
 
        // Get the filelist from the archive
-       struct pakfire_filelist* filelist = pakfire_archive_get_filelist(archive);
-       if (!filelist) {
-               ERROR(db->ctx, "Could not fetch filelist from archive\n");
-               return 1;
+       r = pakfire_archive_get_filelist(archive, &filelist);
+       if (r < 0) {
+               ERROR(db->ctx, "Could not fetch filelist from archive: %s\n", strerror(-r));
+               return r;
        }
 
        // Nothing to do if the list is empty
@@ -1249,9 +1250,10 @@ static int pakfire_db_add_files(struct pakfire_db* db, unsigned long id, struct
        r = 0;
 
 END:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
        if (stmt)
                sqlite3_finalize(stmt);
-       pakfire_filelist_unref(filelist);
 
        return r;
 }
index 3e9585a0ae32820aaa71ef31dbba020dbf409405..5bf5c1aab0e97d5d86c59f1e7a74b53a75cfb854 100644 (file)
@@ -1366,13 +1366,16 @@ static int pakfire_transaction_run_script(struct pakfire_transaction* transactio
 
 static int pakfire_transaction_extract(struct pakfire_transaction* transaction,
                struct pakfire_package* pkg, struct pakfire_archive* archive) {
+       struct pakfire_filelist* filelist = NULL;
+       int r;
+
        const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
 
        // Update status
        pakfire_transaction_status(transaction, _("Installing %s..."), nevra);
 
        // Extract payload
-       int r = pakfire_archive_extract(archive, NULL, 0);
+       r = pakfire_archive_extract(archive, NULL, 0);
        if (r) {
                ERROR(transaction->ctx, "Could not extract package %s: %m\n",
                        nevra);
@@ -1380,18 +1383,18 @@ static int pakfire_transaction_extract(struct pakfire_transaction* transaction,
        }
 
        // Is it necessary to call ldconfig?
-       struct pakfire_filelist* filelist = pakfire_archive_get_filelist(archive);
-       if (filelist) {
-               int need_ldconfig = pakfire_filelist_contains(filelist, "*/lib*.so.?");
+       r = pakfire_archive_get_filelist(archive, &filelist);
+       if (r < 0)
+               return r;
 
-               // Update the runtime linker cache
-               if (need_ldconfig)
-                       pakfire_jail_ldconfig(transaction->pakfire);
+       // Update the runtime linker cache
+       if (pakfire_filelist_contains(filelist, "*/lib*.so.?"))
+               pakfire_jail_ldconfig(transaction->pakfire);
 
+       if (filelist)
                pakfire_filelist_unref(filelist);
-       }
 
-       return r;
+       return 0;
 }
 
 static int pakfire_transaction_erase(struct pakfire_transaction* transaction,
index d6fcae79fa01ca6e64d0510bd7dbe5fe04e56362..34bf128ab7d61d6a3e2a7a931b95bbb0dbf32bd1 100644 (file)
@@ -192,13 +192,16 @@ static PyObject* Archive_get_path(ArchiveObject* self) {
 
 static PyObject* Archive_get_filelist(ArchiveObject* self) {
        struct pakfire_filelist* filelist = NULL;
+       int r;
 
        Py_BEGIN_ALLOW_THREADS
 
        // Fetch the filelist
-       filelist = pakfire_archive_get_filelist(self->archive);
-       if (!filelist) {
+       r = pakfire_archive_get_filelist(self->archive, &filelist);
+       if (r < 0) {
                Py_BLOCK_THREADS
+
+               errno = -r;
                PyErr_SetFromErrno(PyExc_OSError);
                return NULL;
        }
@@ -206,12 +209,12 @@ static PyObject* Archive_get_filelist(ArchiveObject* self) {
        Py_END_ALLOW_THREADS
 
        // Convert to filelist
-       PyObject* _filelist = PyList_FromFileList(filelist);
+       PyObject* result = PyList_FromFileList(filelist);
 
        // Cleanup
        pakfire_filelist_unref(filelist);
 
-       return _filelist;
+       return result;
 }
 
 static struct PyMethodDef Archive_methods[] = {
index b0f14749182a1320c03028781b7e136ef02df340..dc8809b8bf975b60acd531a165f53bb3f9af3fb7 100644 (file)
@@ -169,7 +169,7 @@ static int test_filelist(const struct test* t) {
        ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, TEST_SRC_PATH TEST_PKG1_PATH));
 
        // Fetch the filelist
-       ASSERT(list = pakfire_archive_get_filelist(archive));
+       ASSERT_SUCCESS(pakfire_archive_get_filelist(archive, &list));
 
        // This packages has 7 files
        ASSERT(pakfire_filelist_length(list) == 7);
index 273e3f2d631b70f26776d8afd7084f4d9a0d7851..8a854d422e6398973c38293bdb88dd87c98f0536 100644 (file)
@@ -241,8 +241,7 @@ static int test_dist_dummy(const struct test* t) {
        ASSERT(installed_size == 0);
 
        // Fetch the filelist
-       filelist = pakfire_archive_get_filelist(archive);
-       ASSERT(filelist);
+       ASSERT_SUCCESS(pakfire_archive_get_filelist(archive, &filelist));
 
        // There must be exactly one file in this package
        ASSERT(pakfire_filelist_length(filelist) == 1);