Commit 28dcd5d3 authored by Timo Teräs's avatar Timo Teräs

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.
parent d8ba07e4
...@@ -76,6 +76,7 @@ struct apk_name { ...@@ -76,6 +76,7 @@ struct apk_name {
char *name; char *name;
struct apk_package_array *pkgs; struct apk_package_array *pkgs;
struct apk_name_array *rdepends; struct apk_name_array *rdepends;
struct apk_name_array *rinstall_if;
}; };
struct apk_repository { struct apk_repository {
......
...@@ -85,7 +85,7 @@ struct apk_package { ...@@ -85,7 +85,7 @@ struct apk_package {
apk_blob_t *version, *arch, *license; apk_blob_t *version, *arch, *license;
char *url, *description; char *url, *description;
char *filename; char *filename;
struct apk_dependency_array *depends; struct apk_dependency_array *depends, *install_if;
size_t installed_size, size; size_t installed_size, size;
unsigned repos; unsigned repos;
struct apk_checksum csum; struct apk_checksum csum;
......
...@@ -84,6 +84,7 @@ static void pkg_name_free(struct apk_name *name) ...@@ -84,6 +84,7 @@ static void pkg_name_free(struct apk_name *name)
free(name->name); free(name->name);
apk_package_array_free(&name->pkgs); apk_package_array_free(&name->pkgs);
apk_name_array_free(&name->rdepends); apk_name_array_free(&name->rdepends);
apk_name_array_free(&name->rinstall_if);
free(name); free(name);
} }
...@@ -196,6 +197,7 @@ struct apk_name *apk_db_get_name(struct apk_database *db, apk_blob_t 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++; pn->id = db->name_id++;
apk_package_array_init(&pn->pkgs); apk_package_array_init(&pn->pkgs);
apk_name_array_init(&pn->rdepends); apk_name_array_init(&pn->rdepends);
apk_name_array_init(&pn->rinstall_if);
apk_hash_insert_hashed(&db->available.names, pn, hash); apk_hash_insert_hashed(&db->available.names, pn, hash);
return pn; return pn;
...@@ -399,16 +401,25 @@ static struct apk_db_file *apk_db_file_get(struct apk_database *db, ...@@ -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) static void apk_db_pkg_rdepends(struct apk_database *db, struct apk_package *pkg)
{ {
int i, j; int i, j;
struct apk_name *rname;
for (i = 0; i < pkg->depends->num; i++) { 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++) for (j = 0; j < rname->rdepends->num; j++)
if (rname->rdepends->item[j] == pkg->name) if (rname->rdepends->item[j] == pkg->name)
return; goto rdeps_done;
*apk_name_array_add(&rname->rdepends) = pkg->name; *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) struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg)
......
...@@ -58,8 +58,10 @@ struct apk_package *apk_pkg_new(void) ...@@ -58,8 +58,10 @@ struct apk_package *apk_pkg_new(void)
struct apk_package *pkg; struct apk_package *pkg;
pkg = calloc(1, sizeof(struct apk_package)); pkg = calloc(1, sizeof(struct apk_package));
if (pkg != NULL) if (pkg != NULL) {
apk_dependency_array_init(&pkg->depends); apk_dependency_array_init(&pkg->depends);
apk_dependency_array_init(&pkg->install_if);
}
return pkg; return pkg;
} }
...@@ -654,6 +656,9 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg, ...@@ -654,6 +656,9 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
case 'I': case 'I':
pkg->installed_size = apk_blob_pull_uint(&value, 10); pkg->installed_size = apk_blob_pull_uint(&value, 10);
break; break;
case 'i':
apk_deps_parse(db, &pkg->install_if, value);
break;
case 'F': case 'M': case 'R': case 'Z': case 'F': case 'M': case 'R': case 'Z':
/* installed db entries which are handled in database.c */ /* installed db entries which are handled in database.c */
return 1; return 1;
...@@ -677,14 +682,15 @@ static int read_info_line(void *ctx, apk_blob_t line) ...@@ -677,14 +682,15 @@ static int read_info_line(void *ctx, apk_blob_t line)
const char *str; const char *str;
char field; char field;
} fields[] = { } fields[] = {
{ "pkgname", 'P' }, { "pkgname", 'P' },
{ "pkgver", 'V' }, { "pkgver", 'V' },
{ "pkgdesc", 'T' }, { "pkgdesc", 'T' },
{ "url", 'U' }, { "url", 'U' },
{ "size", 'I' }, { "size", 'I' },
{ "license", 'L' }, { "license", 'L' },
{ "arch", 'A' }, { "arch", 'A' },
{ "depend", 'D' }, { "depend", 'D' },
{ "install_if", 'i' },
}; };
struct read_info_ctx *ri = (struct read_info_ctx *) ctx; struct read_info_ctx *ri = (struct read_info_ctx *) ctx;
apk_blob_t l, r; apk_blob_t l, r;
...@@ -789,6 +795,7 @@ void apk_pkg_free(struct apk_package *pkg) ...@@ -789,6 +795,7 @@ void apk_pkg_free(struct apk_package *pkg)
apk_pkg_uninstall(NULL, pkg); apk_pkg_uninstall(NULL, pkg);
apk_dependency_array_free(&pkg->depends); apk_dependency_array_free(&pkg->depends);
apk_dependency_array_free(&pkg->install_if);
if (pkg->url) if (pkg->url)
free(pkg->url); free(pkg->url);
if (pkg->description) if (pkg->description)
...@@ -916,12 +923,30 @@ struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_ ...@@ -916,12 +923,30 @@ struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_
return ctx.pkg; 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, int apk_pkg_write_index_entry(struct apk_package *info,
struct apk_ostream *os) struct apk_ostream *os)
{ {
char buf[512]; char buf[512];
apk_blob_t bbuf = APK_BLOB_BUF(buf); apk_blob_t bbuf = APK_BLOB_BUF(buf);
int r;
apk_blob_push_blob(&bbuf, APK_BLOB_STR("C:")); apk_blob_push_blob(&bbuf, APK_BLOB_STR("C:"));
apk_blob_push_csum(&bbuf, &info->csum); apk_blob_push_csum(&bbuf, &info->csum);
...@@ -949,19 +974,11 @@ int apk_pkg_write_index_entry(struct apk_package *info, ...@@ -949,19 +974,11 @@ int apk_pkg_write_index_entry(struct apk_package *info,
return -1; return -1;
bbuf = apk_blob_pushed(APK_BLOB_BUF(buf), bbuf); 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; 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; return 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment