]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Raise and log better errors when a package could not be read
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 22:54:13 +0000 (23:54 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Jun 2019 22:54:13 +0000 (23:54 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/archive.c
src/libpakfire/archive.c

index 52bb3fdf675feaaa678d622ebbd6cdb3111b52e5..7e3b72002fcf449dd7f32cb1076d1cf763d0b096 100644 (file)
@@ -52,8 +52,10 @@ static int Archive_init(ArchiveObject* self, PyObject* args, PyObject* kwds) {
                return -1;
 
        self->archive = pakfire_archive_open(pakfire->pakfire, filename);
-       if (!self->archive)
+       if (!self->archive) {
+               PyErr_SetFromErrno(PyExc_OSError);
                return -1;
+       }
 
        return 0;
 }
index 56c1a372501f99ff74324d7939d6d90a14eb29b1..473676a16a99ccc5a62db0652e24cf39a8cd7423 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <assert.h>
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <gpgme.h>
 #include <stdlib.h>
@@ -100,6 +101,10 @@ static int archive_open(PakfireArchive archive, struct archive** a) {
                return 0;
        }
 
+       // Log error message
+       const char* error = archive_error_string(*a);
+       DEBUG(archive->pakfire, "Could not open archive: %s\n", error);
+
        archive_read_free(*a);
        *a = NULL;
 
@@ -631,6 +636,11 @@ PAKFIRE_EXPORT PakfireArchive pakfire_archive_open(Pakfire pakfire, const char*
        // Stat the file and store the result
        int r = stat(archive->path, &archive->stat);
        if (r) {
+               pakfire_errno = errno;
+
+               ERROR(pakfire, "Could not stat %s: %s\n",
+                       archive->path, strerror(pakfire_errno));
+
                goto error;
        }
 
@@ -638,14 +648,16 @@ PAKFIRE_EXPORT PakfireArchive pakfire_archive_open(Pakfire pakfire, const char*
        struct archive* a;
        r = archive_open(archive, &a);
        if (r) {
-               pakfire_errno = r;
+               pakfire_errno = PAKFIRE_E_PKG_INVALID;
                goto error;
        }
 
        // Parse all entries in the archive.
        r = pakfire_archive_read_metadata(archive, a);
        if (r) {
-               pakfire_errno = r;
+               ERROR(pakfire, "Could not read metadata from %s\n", archive->path);
+
+               pakfire_errno = PAKFIRE_E_PKG_INVALID;
                goto error;
        }