Commit d8ba07e4 authored by Timo Teräs's avatar Timo Teräs

pkg, db: allow index with unsupported features to be loaded

Just disable installation of packages using the new stuff. Also
flag lower case package info fields as non-critical and allow
installation even if that features is not supported.
parent 1f42cc1a
...@@ -105,8 +105,10 @@ struct apk_database { ...@@ -105,8 +105,10 @@ struct apk_database {
unsigned name_id, num_repos; unsigned name_id, num_repos;
const char *cache_dir; const char *cache_dir;
apk_blob_t *arch; apk_blob_t *arch;
int permanent;
unsigned int local_repos; unsigned int local_repos;
int permanent : 1;
int compat_newfeatures : 1;
int compat_notinstallable : 1;
struct apk_dependency_array *world; struct apk_dependency_array *world;
struct apk_string_array *protected_paths; struct apk_string_array *protected_paths;
......
...@@ -76,6 +76,8 @@ struct apk_installed_package { ...@@ -76,6 +76,8 @@ struct apk_installed_package {
struct apk_string_array *pending_triggers; struct apk_string_array *pending_triggers;
}; };
#define APK_PKG_UNINSTALLABLE ((char*) -1)
struct apk_package { struct apk_package {
apk_hash_node hash_node; apk_hash_node hash_node;
struct apk_name *name; struct apk_name *name;
......
...@@ -562,7 +562,7 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -562,7 +562,7 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
struct hlist_node **diri_node = NULL; struct hlist_node **diri_node = NULL;
struct hlist_node **file_diri_node = NULL; struct hlist_node **file_diri_node = NULL;
apk_blob_t token = APK_BLOB_STR("\n"), l; apk_blob_t token = APK_BLOB_STR("\n"), l;
int field; int field, r;
while (!APK_BLOB_IS_NULL(l = bs->read(bs, token))) { while (!APK_BLOB_IS_NULL(l = bs->read(bs, token))) {
if (l.len < 2 || l.ptr[1] != ':') { if (l.len < 2 || l.ptr[1] != ':') {
...@@ -589,27 +589,25 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -589,27 +589,25 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
/* If no package, create new */ /* If no package, create new */
if (pkg == NULL) { if (pkg == NULL) {
pkg = apk_pkg_new(); pkg = apk_pkg_new();
ipkg = NULL; ipkg = NULL;
diri = NULL; diri = NULL;
file_diri_node = NULL; file_diri_node = NULL;
} }
/* Standard index line? */ /* Standard index line? */
if (apk_pkg_add_info(db, pkg, field, l) == 0) { r = apk_pkg_add_info(db, pkg, field, l);
if (repo == -1 && field == 'S') { if (r == 0) {
/* Instert to installed database; this needs to if (repo == -1 && field == 'S') {
* happen after package name has been read, but /* Instert to installed database; this needs to
* before first FDB entry. */ * happen after package name has been read, but
ipkg = apk_pkg_install(db, pkg); * before first FDB entry. */
diri_node = hlist_tail_ptr(&ipkg->owned_dirs); ipkg = apk_pkg_install(db, pkg);
} diri_node = hlist_tail_ptr(&ipkg->owned_dirs);
}
continue; continue;
}
if (repo != -1 || ipkg == NULL) {
apk_error("Invalid index entry '%c'", field);
return -1;
} }
if (repo != -1 || ipkg == NULL)
continue;
/* Check FDB special entries */ /* Check FDB special entries */
switch (field) { switch (field) {
...@@ -647,8 +645,14 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo) ...@@ -647,8 +645,14 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
apk_blob_pull_csum(&l, &file->csum); apk_blob_pull_csum(&l, &file->csum);
break; break;
default: default:
apk_error("FDB entry '%c' unsupported", field); if (r != 0 && !(apk_flags & APK_FORCE)) {
return -1; /* Installed db should not have unsupported fields */
apk_error("This apk-tools is too old to handle installed packages");
return -1;
}
/* Installed. So mark the package as installable. */
pkg->filename = NULL;
continue;
} }
if (APK_BLOB_IS_NULL(l)) { if (APK_BLOB_IS_NULL(l)) {
apk_error("FDB format error in entry '%c'", field); apk_error("FDB format error in entry '%c'", field);
...@@ -879,7 +883,7 @@ static int apk_db_read_state(struct apk_database *db, int flags) ...@@ -879,7 +883,7 @@ static int apk_db_read_state(struct apk_database *db, int flags)
struct apk_istream *is; struct apk_istream *is;
struct apk_bstream *bs; struct apk_bstream *bs;
apk_blob_t blob; apk_blob_t blob;
int i; int i, r;
/* Read: /* Read:
* 1. installed repository * 1. installed repository
...@@ -903,8 +907,10 @@ static int apk_db_read_state(struct apk_database *db, int flags) ...@@ -903,8 +907,10 @@ static int apk_db_read_state(struct apk_database *db, int flags)
if (!(flags & APK_OPENF_NO_INSTALLED)) { if (!(flags & APK_OPENF_NO_INSTALLED)) {
bs = apk_bstream_from_file(db->root_fd, "var/lib/apk/installed"); bs = apk_bstream_from_file(db->root_fd, "var/lib/apk/installed");
if (bs != NULL) { if (bs != NULL) {
apk_db_index_read(db, bs, -1); r = apk_db_index_read(db, bs, -1);
bs->close(bs, NULL); bs->close(bs, NULL);
if (r != 0)
return -1;
} }
bs = apk_bstream_from_file(db->root_fd, "var/lib/apk/triggers"); bs = apk_bstream_from_file(db->root_fd, "var/lib/apk/triggers");
...@@ -1182,6 +1188,13 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) ...@@ -1182,6 +1188,13 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
goto ret_r; goto ret_r;
} }
if (db->compat_newfeatures) {
apk_warning("This apk-tools is OLD! Some packages %s.",
db->compat_notinstallable ?
"are not installable" :
"might not function properly");
}
return rr; return rr;
ret_errno: ret_errno:
......
...@@ -654,8 +654,17 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg, ...@@ -654,8 +654,17 @@ 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 'F': case 'M': case 'R': case 'Z':
/* installed db entries which are handled in database.c */
return 1;
default: default:
return -1; /* lower case index entries are safe to be ignored */
if (!islower(field)) {
pkg->filename = APK_PKG_UNINSTALLABLE;
db->compat_notinstallable = 1;
}
db->compat_newfeatures = 1;
return 1;
} }
if (APK_BLOB_IS_NULL(value)) if (APK_BLOB_IS_NULL(value))
return -1; return -1;
...@@ -755,8 +764,9 @@ int apk_pkg_read(struct apk_database *db, const char *file, ...@@ -755,8 +764,9 @@ int apk_pkg_read(struct apk_database *db, const char *file,
tar->close(tar); tar->close(tar);
if (r < 0 && r != -ECANCELED) if (r < 0 && r != -ECANCELED)
goto err; goto err;
if (ctx.pkg->name == NULL) { if (ctx.pkg->name == NULL ||
r = -ENOMSG; ctx.pkg->filename == APK_PKG_UNINSTALLABLE) {
r = -ENOTSUP;
goto err; goto err;
} }
if (sctx->action != APK_SIGN_VERIFY) if (sctx->action != APK_SIGN_VERIFY)
......
...@@ -119,6 +119,15 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db, ...@@ -119,6 +119,15 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db,
memcpy(nc->pkgs, name->pkgs->item, memcpy(nc->pkgs, name->pkgs->item,
name->pkgs->num * sizeof(struct apk_package *)); name->pkgs->num * sizeof(struct apk_package *));
for (j = 0; j < nc->num; ) {
if (nc->pkgs[j]->filename != APK_PKG_UNINSTALLABLE) {
j++;
} else {
nc->pkgs[j] = nc->pkgs[nc->num - 1];
nc->num--;
}
}
if (name->flags & APK_NAME_TOPLEVEL_OVERRIDE) if (name->flags & APK_NAME_TOPLEVEL_OVERRIDE)
return nc; return nc;
...@@ -131,7 +140,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db, ...@@ -131,7 +140,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db,
for (j = 0; j < nc->num; ) { for (j = 0; j < nc->num; ) {
if (apk_dep_is_satisfied(dep, nc->pkgs[j])) { if (apk_dep_is_satisfied(dep, nc->pkgs[j])) {
j++; j++;
} else { } else {
nc->pkgs[j] = nc->pkgs[nc->num - 1]; nc->pkgs[j] = nc->pkgs[nc->num - 1];
nc->num--; nc->num--;
......
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