summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-01-04 10:05:20 +0200
committerTimo Teräs <timo.teras@iki.fi>2011-01-04 10:05:20 +0200
commit28dcd5d3b341eb16fceb6cd362e5dd6875b4467b (patch)
tree3c502f74bbf401ce72ccc845e33953f8d71eaf3d /src/package.c
parentd8ba07e484b0c838ce475202f03e041953b183e1 (diff)
downloadapk-tools-28dcd5d3b341eb16fceb6cd362e5dd6875b4467b.tar.gz
apk-tools-28dcd5d3b341eb16fceb6cd362e5dd6875b4467b.tar.bz2
apk-tools-28dcd5d3b341eb16fceb6cd362e5dd6875b4467b.tar.xz
apk-tools-28dcd5d3b341eb16fceb6cd362e5dd6875b4467b.zip
pkg: recognize install_if
Parse install_if from package metadata and include it in the indexes. Also setup the reverse install_if dependencies when loading a database. ref #443. Actual install_if functionality is not yet implemented.
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/package.c b/src/package.c
index ae34f79..1a5d502 100644
--- a/src/package.c
+++ b/src/package.c
@@ -58,8 +58,10 @@ struct apk_package *apk_pkg_new(void)
struct apk_package *pkg;
pkg = calloc(1, sizeof(struct apk_package));
- if (pkg != NULL)
+ if (pkg != NULL) {
apk_dependency_array_init(&pkg->depends);
+ apk_dependency_array_init(&pkg->install_if);
+ }
return pkg;
}
@@ -654,6 +656,9 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
case 'I':
pkg->installed_size = apk_blob_pull_uint(&value, 10);
break;
+ case 'i':
+ apk_deps_parse(db, &pkg->install_if, value);
+ break;
case 'F': case 'M': case 'R': case 'Z':
/* installed db entries which are handled in database.c */
return 1;
@@ -677,14 +682,15 @@ static int read_info_line(void *ctx, apk_blob_t line)
const char *str;
char field;
} fields[] = {
- { "pkgname", 'P' },
- { "pkgver", 'V' },
- { "pkgdesc", 'T' },
- { "url", 'U' },
- { "size", 'I' },
- { "license", 'L' },
- { "arch", 'A' },
- { "depend", 'D' },
+ { "pkgname", 'P' },
+ { "pkgver", 'V' },
+ { "pkgdesc", 'T' },
+ { "url", 'U' },
+ { "size", 'I' },
+ { "license", 'L' },
+ { "arch", 'A' },
+ { "depend", 'D' },
+ { "install_if", 'i' },
};
struct read_info_ctx *ri = (struct read_info_ctx *) ctx;
apk_blob_t l, r;
@@ -789,6 +795,7 @@ void apk_pkg_free(struct apk_package *pkg)
apk_pkg_uninstall(NULL, pkg);
apk_dependency_array_free(&pkg->depends);
+ apk_dependency_array_free(&pkg->install_if);
if (pkg->url)
free(pkg->url);
if (pkg->description)
@@ -916,12 +923,30 @@ struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_
return ctx.pkg;
}
+static int write_depends(struct apk_ostream *os, const char *field,
+ struct apk_dependency_array *deps)
+{
+ int r;
+
+ if (deps->num == 0)
+ return 0;
+
+ if (os->write(os, field, 2) != 2)
+ return -1;
+ r = apk_deps_write(deps, os);
+ if (r < 0)
+ return r;
+ if (os->write(os, "\n", 1) != 1)
+ return -1;
+
+ return 0;
+}
+
int apk_pkg_write_index_entry(struct apk_package *info,
struct apk_ostream *os)
{
char buf[512];
apk_blob_t bbuf = APK_BLOB_BUF(buf);
- int r;
apk_blob_push_blob(&bbuf, APK_BLOB_STR("C:"));
apk_blob_push_csum(&bbuf, &info->csum);
@@ -949,19 +974,11 @@ int apk_pkg_write_index_entry(struct apk_package *info,
return -1;
bbuf = apk_blob_pushed(APK_BLOB_BUF(buf), bbuf);
- if (os->write(os, bbuf.ptr, bbuf.len) != bbuf.len)
+ if (os->write(os, bbuf.ptr, bbuf.len) != bbuf.len ||
+ write_depends(os, "D:", info->depends) ||
+ write_depends(os, "i:", info->install_if))
return -1;
- if (info->depends->num > 0) {
- if (os->write(os, "D:", 2) != 2)
- return -1;
- r = apk_deps_write(info->depends, os);
- if (r < 0)
- return r;
- if (os->write(os, "\n", 1) != 1)
- return -1;
- }
-
return 0;
}