summaryrefslogtreecommitdiff
path: root/src/app_index.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app_index.c')
-rw-r--r--src/app_index.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/app_index.c b/src/app_index.c
index e37d0af..56fbe7c 100644
--- a/src/app_index.c
+++ b/src/app_index.c
@@ -75,6 +75,33 @@ static const struct apk_option_group optgroup_applet = {
.parse = option_parse_applet,
};
+struct index_writer {
+ struct apk_ostream *os;
+ int count;
+};
+
+static int index_write_entry(struct apk_database *db, const char *match, struct apk_package *pkg, void *ctx)
+{
+ struct index_writer *iw = ctx;
+
+ if (!pkg->filename) return 0;
+
+ iw->count++;
+ apk_pkg_write_index_entry(pkg, iw->os);
+ return 0;
+}
+
+static int index_write(struct apk_database *db, struct apk_ostream *os)
+{
+ struct index_writer iw = {
+ .os = os,
+ };
+
+ apk_db_foreach_sorted_package(db, NULL, index_write_entry, &iw);
+
+ return iw.count;
+}
+
static int index_read_file(struct apk_database *db, struct index_ctx *ictx)
{
struct apk_file_info fi;
@@ -208,7 +235,7 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
fi.mode = 0644 | S_IFREG;
fi.name = "APKINDEX";
counter = apk_ostream_counter(&fi.size);
- r = apk_db_index_write(db, counter);
+ r = index_write(db, counter);
apk_ostream_close(counter);
if (r >= 0) {
@@ -223,13 +250,13 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
}
apk_tar_write_entry(os, &fi, NULL);
- r = apk_db_index_write(db, os);
+ r = index_write(db, os);
apk_tar_write_padding(os, &fi);
apk_tar_write_entry(os, NULL, NULL);
}
} else {
- r = apk_db_index_write(db, os);
+ r = index_write(db, os);
}
apk_ostream_close(os);