diff options
-rw-r--r-- | src/apk_package.h | 1 | ||||
-rw-r--r-- | src/database.c | 8 | ||||
-rw-r--r-- | src/package.c | 23 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/apk_package.h b/src/apk_package.h index c6eaa1c..bf0ae95 100644 --- a/src/apk_package.h +++ b/src/apk_package.h @@ -68,6 +68,7 @@ void apk_deps_parse(struct apk_database *db, apk_blob_t blob); int apk_deps_format(char *buf, int size, struct apk_dependency_array *depends); +int apk_deps_write(struct apk_dependency_array *deps, struct apk_ostream *os); int apk_script_type(const char *name); struct apk_package *apk_pkg_new(void); diff --git a/src/database.c b/src/database.c index 27b49ea..976102b 100644 --- a/src/database.c +++ b/src/database.c @@ -725,8 +725,6 @@ struct write_ctx { static int apk_db_write_config(struct apk_database *db) { struct apk_ostream *os; - char buf[1024]; - int n; if (db->root == NULL) return 0; @@ -741,10 +739,8 @@ static int apk_db_write_config(struct apk_database *db) os = apk_ostream_to_file("var/lib/apk/world", 0644); if (os == NULL) return -1; - n = apk_deps_format(buf, sizeof(buf), db->world); - if (n < sizeof(buf)) - buf[n++] = '\n'; - os->write(os, buf, n); + apk_deps_write(db->world, os); + os->write(os, "\n", 1); os->close(os); os = apk_ostream_to_file("var/lib/apk/installed.new", 0644); diff --git a/src/package.c b/src/package.c index a5e988b..4d9f33d 100644 --- a/src/package.c +++ b/src/package.c @@ -149,6 +149,29 @@ int apk_deps_format(char *buf, int size, return n; } +int apk_deps_write(struct apk_dependency_array *deps, struct apk_ostream *os) +{ + int i, len, n = 0; + + if (deps == NULL) + return 0; + + for (i = 0; i < deps->num; i++) { + if (i) { + if (os->write(os, " ", 1) != 1) + return -1; + n += 1; + } + + len = strlen(deps->item[i].name->name); + if (os->write(os, deps->item[i].name->name, len) != len) + return -1; + n += len; + } + + return n; +} + static const char *script_types[] = { [APK_SCRIPT_PRE_INSTALL] = "pre-install", [APK_SCRIPT_POST_INSTALL] = "post-install", |