From 621c23fcde829ff8e1056156173619fdcda0ad38 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 29 Nov 2022 17:10:04 +0000 Subject: [PATCH] repo: Slightly refactor scanning No functional changes. Signed-off-by: Michael Tremer --- src/libpakfire/repo.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 2b72e3172..80423d970 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -1166,28 +1166,33 @@ PAKFIRE_EXPORT int pakfire_repo_clean(struct pakfire_repo* repo, int flags) { } static int pakfire_repo_scan_file(struct pakfire_repo* repo, const char* path) { - DEBUG(repo->pakfire, "Scanning %s...\n", path); - struct pakfire_archive* archive = NULL; struct pakfire_package* package = NULL; + int r; + + DEBUG(repo->pakfire, "Scanning %s...\n", path); // Open archive - int r = pakfire_archive_open(&archive, repo->pakfire, path); + r = pakfire_archive_open(&archive, repo->pakfire, path); if (r) - return r; + goto ERROR; // Import package into the repository r = pakfire_archive_make_package(archive, repo, &package); +ERROR: if (package) pakfire_package_unref(package); - pakfire_archive_unref(archive); + if (archive) + pakfire_archive_unref(archive); return r; } PAKFIRE_EXPORT int pakfire_repo_scan(struct pakfire_repo* repo, int flags) { + struct pakfire_filelist* filelist = NULL; struct pakfire_progressbar* progressbar = NULL; + int r; const char* path = pakfire_repo_get_path(repo); if (!path) { @@ -1195,17 +1200,17 @@ PAKFIRE_EXPORT int pakfire_repo_scan(struct pakfire_repo* repo, int flags) { return 1; } - struct pakfire_filelist* filelist; - int r = pakfire_filelist_create(&filelist, repo->pakfire); + // Create a new filelist + r = pakfire_filelist_create(&filelist, repo->pakfire); if (r) - return r; + goto ERROR; static const char* includes[] = { "*.pfm", NULL }; // Find all package files r = pakfire_filelist_scan(filelist, path, includes, NULL); if (r) - return r; + goto ERROR; // Fetch how many files have been found const size_t num_files = pakfire_filelist_size(filelist); @@ -1274,7 +1279,8 @@ PAKFIRE_EXPORT int pakfire_repo_scan(struct pakfire_repo* repo, int flags) { ERROR: if (progressbar) pakfire_progressbar_unref(progressbar); - pakfire_filelist_unref(filelist); + if (filelist) + pakfire_filelist_unref(filelist); return r; } -- 2.39.5