summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/apk_database.h1
-rw-r--r--src/apk_package.h2
-rw-r--r--src/database.c19
-rw-r--r--src/package.c59
4 files changed, 55 insertions, 26 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index 070b3a6..b79253d 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -76,6 +76,7 @@ struct apk_name {
char *name;
struct apk_package_array *pkgs;
struct apk_name_array *rdepends;
+ struct apk_name_array *rinstall_if;
};
struct apk_repository {
diff --git a/src/apk_package.h b/src/apk_package.h
index 8998c7c..ed25bd4 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -85,7 +85,7 @@ struct apk_package {
apk_blob_t *version, *arch, *license;
char *url, *description;
char *filename;
- struct apk_dependency_array *depends;
+ struct apk_dependency_array *depends, *install_if;
size_t installed_size, size;
unsigned repos;
struct apk_checksum csum;
diff --git a/src/database.c b/src/database.c
index d7692cd..c1e8a6a 100644
--- a/src/database.c
+++ b/src/database.c
@@ -84,6 +84,7 @@ static void pkg_name_free(struct apk_name *name)
free(name->name);
apk_package_array_free(&name->pkgs);
apk_name_array_free(&name->rdepends);
+ apk_name_array_free(&name->rinstall_if);
free(name);
}
@@ -196,6 +197,7 @@ struct apk_name *apk_db_get_name(struct apk_database *db, apk_blob_t name)
pn->id = db->name_id++;
apk_package_array_init(&pn->pkgs);
apk_name_array_init(&pn->rdepends);
+ apk_name_array_init(&pn->rinstall_if);
apk_hash_insert_hashed(&db->available.names, pn, hash);
return pn;
@@ -399,16 +401,25 @@ static struct apk_db_file *apk_db_file_get(struct apk_database *db,
static void apk_db_pkg_rdepends(struct apk_database *db, struct apk_package *pkg)
{
int i, j;
+ struct apk_name *rname;
for (i = 0; i < pkg->depends->num; i++) {
- struct apk_name *rname = pkg->depends->item[i].name;
-
+ rname = pkg->depends->item[i].name;
for (j = 0; j < rname->rdepends->num; j++)
if (rname->rdepends->item[j] == pkg->name)
- return;
-
+ goto rdeps_done;
*apk_name_array_add(&rname->rdepends) = pkg->name;
}
+rdeps_done:
+ for (i = 0; i < pkg->install_if->num; i++) {
+ rname = pkg->install_if->item[i].name;
+ for (j = 0; j < rname->rinstall_if->num; j++)
+ if (rname->rinstall_if->item[j] == pkg->name)
+ goto riif_done;
+ *apk_name_array_add(&rname->rinstall_if) = pkg->name;
+ }
+riif_done:
+ return;
}
struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg)
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;
}