]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: pakfire_create: Return a better return code
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 11:33:49 +0000 (11:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 12:58:49 +0000 (12:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/pakfire.c

index 99035637a28bc9ca86ffdfc6b9f2a8e329268f96..27fe098ed7eb96241c221f0d41d5535639c817cc 100644 (file)
@@ -220,7 +220,9 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
 
        Py_END_ALLOW_THREADS
 
-       if (r) {
+       if (r < 0) {
+               errno = -r;
+
                switch (errno) {
                        // Invalid architecture or path
                        case EINVAL:
index 8c3c3fd679cf275927f6bcc0260399f854ee9ae3..0544d756b031ce458a19b45294286c0a11eeb508 100644 (file)
@@ -828,7 +828,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
 
        struct pakfire* p = calloc(1, sizeof(*p));
        if (!p)
-               return 1;
+               return -errno;
 
        p->nrefs = 1;
        p->flags = flags;
@@ -852,7 +852,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        // Check if the architecture is supported
        if (!pakfire_arch_supported(arch)) {
                ERROR(p, "Unsupported architecture: %s\n", arch);
-               errno = EINVAL;
+               r = -EINVAL;
                goto ERROR;
        }
 
@@ -862,7 +862,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        // Path must be absolute
        if (path && !pakfire_string_startswith(path, "/")) {
                ERROR(p, "Invalid path: %s\n", path);
-               errno = EINVAL;
+               r = -EINVAL;
                goto ERROR;
        }
 
@@ -870,7 +870,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
        if (!path) {
                path = pakfire_mkdtemp(tempdir);
                if (!path) {
-                       r = 1;
+                       r = -errno;
                        goto ERROR;
                }
 
@@ -1016,8 +1016,7 @@ int pakfire_acquire_lock(struct pakfire* pakfire) {
        // Check if the lock is already held
        if (pakfire->lock) {
                ERROR(pakfire, "Lock is already been acquired by this process\n");
-               errno = ENOLCK;
-               return 1;
+               return -ENOLCK;
        }
 
        DEBUG(pakfire, "Acquire lock...\n");
@@ -1029,7 +1028,7 @@ int pakfire_acquire_lock(struct pakfire* pakfire) {
        pakfire->lock = fopen(pakfire->lock_path, "w");
        if (!pakfire->lock) {
                ERROR(pakfire, "Could not open lock file %s: %m\n", pakfire->lock_path);
-               return 1;
+               return -errno;
        }
 
        // Attempt to lock the file exclusively