]> git.ipfire.org Git - pakfire.git/commitdiff
archive: Cleanup loop when searching for files
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 17:38:51 +0000 (17:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Oct 2024 17:38:51 +0000 (17:38 +0000)
This mainly removes the ugly label jump.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/archive.c

index e1342db1324b993919ad7a3577c56a3e3667de18..d68100c28101d861162282b3982494c65b3058e5 100644 (file)
@@ -930,37 +930,43 @@ PAKFIRE_EXPORT FILE* pakfire_archive_read(struct pakfire_archive* archive, const
                goto ERROR;
        }
 
-       // Open the archive
-AGAIN:
-       cookie->a = open_archive(archive);
-       if (!cookie->a)
-               goto ERROR;
+       for (;;) {
+               // Close any previously opened archives
+               if (cookie->a)
+                       archive_read_free(cookie->a);
 
-       // Walk through the archive
-       r = pakfire_archive_walk(archive, cookie->a, __pakfire_archive_read,
-                       pakfire_archive_read_filter, cookie);
-       if (r) {
+               // Open the archive
+               cookie->a = open_archive(archive);
+               if (!cookie->a)
+                       goto ERROR;
+
+               // Walk through the archive
+               r = pakfire_archive_walk(archive, cookie->a,
+                               __pakfire_archive_read, pakfire_archive_read_filter, cookie);
                switch (-r) {
+                       // Success
+                       case 0:
+                               break;
+
+                       // We have updated the path and need to search again...
                        case EAGAIN:
-                               if (cookie->a)
-                                       archive_read_free(cookie->a);
-                               goto AGAIN;
+                               continue;
 
                        default:
                                goto ERROR;
                }
-       }
 
-       // Nothing found
-       if (!cookie->f) {
-               CTX_ERROR(archive->ctx, "Could not find /%s\n", path);
+               // Nothing found
+               if (!cookie->f) {
+                       CTX_ERROR(archive->ctx, "Could not find /%s\n", path);
 
-               // No such file or directory
-               errno = ENOENT;
-               goto ERROR;
-       }
+                       // No such file or directory
+                       errno = ENOENT;
+                       goto ERROR;
+               }
 
-       return cookie->f;
+               return cookie->f;
+       }
 
 ERROR:
        if (cookie)