summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-04-12 12:45:57 +0300
committerTimo Teräs <timo.teras@iki.fi>2023-04-12 12:48:22 +0300
commit539c8fabb2ebed9f5965b6d0e76b49ffc66147b9 (patch)
tree8a7fb02141dbdb1f05debd0e103a89837a472ccb
parent66326a983ca670bdc55020efb20f2942faa109f2 (diff)
downloadapk-tools-539c8fabb2ebed9f5965b6d0e76b49ffc66147b9.tar.gz
apk-tools-539c8fabb2ebed9f5965b6d0e76b49ffc66147b9.tar.bz2
apk-tools-539c8fabb2ebed9f5965b6d0e76b49ffc66147b9.tar.xz
apk-tools-539c8fabb2ebed9f5965b6d0e76b49ffc66147b9.zip
db, index: clean up index writing error handling
-rw-r--r--src/app_index.c33
-rw-r--r--src/database.c4
2 files changed, 16 insertions, 21 deletions
diff --git a/src/app_index.c b/src/app_index.c
index 02fe30d..65e1fba 100644
--- a/src/app_index.c
+++ b/src/app_index.c
@@ -260,28 +260,25 @@ static int index_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *ar
fi.mode = 0644 | S_IFREG;
fi.name = "APKINDEX";
counter = apk_ostream_counter(&fi.size);
- r = index_write(ictx, db, counter);
+ index_write(ictx, db, counter);
apk_ostream_close(counter);
- if (r >= 0) {
- os = apk_ostream_gzip(os);
- if (ictx->description != NULL) {
- struct apk_file_info fi_desc;
- memset(&fi_desc, 0, sizeof(fi));
- fi_desc.mode = 0644 | S_IFREG;
- fi_desc.name = "DESCRIPTION";
- fi_desc.size = strlen(ictx->description);
- apk_tar_write_entry(os, &fi_desc, ictx->description);
- }
-
- apk_tar_write_entry(os, &fi, NULL);
- r = index_write(ictx, db, os);
- apk_tar_write_padding(os, &fi);
-
- apk_tar_write_entry(os, NULL, NULL);
+ os = apk_ostream_gzip(os);
+ if (ictx->description) {
+ struct apk_file_info fi_desc;
+ memset(&fi_desc, 0, sizeof(fi));
+ fi_desc.mode = 0644 | S_IFREG;
+ fi_desc.name = "DESCRIPTION";
+ fi_desc.size = strlen(ictx->description);
+ apk_tar_write_entry(os, &fi_desc, ictx->description);
}
- apk_ostream_close(os);
+ apk_tar_write_entry(os, &fi, NULL);
+ index_write(ictx, db, os);
+ apk_tar_write_padding(os, &fi);
+ apk_tar_write_entry(os, NULL, NULL);
+
+ r = apk_ostream_close(os);
if (r < 0) {
apk_err(out, "Index generation failed: %s", apk_error_str(r));
return r;
diff --git a/src/database.c b/src/database.c
index 3c50389..e311953 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1243,7 +1243,6 @@ static int apk_db_index_write_nr_cache(struct apk_database *db)
struct apk_package_array *pkgs;
struct apk_package **ppkg;
struct apk_ostream *os;
- int r;
if (!apk_db_cache_active(db)) return 0;
@@ -1257,8 +1256,7 @@ static int apk_db_index_write_nr_cache(struct apk_database *db)
struct apk_package *pkg = *ppkg;
if ((pkg->repos == BIT(APK_REPOSITORY_CACHED) ||
(pkg->repos == 0 && !pkg->installed_size))) {
- r = apk_pkg_write_index_entry(pkg, os);
- if (r != 0) return r;
+ if (apk_pkg_write_index_entry(pkg, os) < 0) break;
}
}
return apk_ostream_close(os);