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

solver, upgrade: properly detect missing repository tags

 * upgrade needs explicit check so we don't try self-upgrade
   (which would print additional messages on screen)
 * add can fix problems, so check against the new world
 * merge the code in few places
parent eaaba3ee
...@@ -107,7 +107,6 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) ...@@ -107,7 +107,6 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
} }
apk_dep_from_pkg(&dep, db, pkg); apk_dep_from_pkg(&dep, db, pkg);
} else { } else {
struct apk_repository_tag *tag;
apk_blob_t b = APK_BLOB_STR(argv[i]); apk_blob_t b = APK_BLOB_STR(argv[i]);
apk_blob_pull_dep(&b, db, &dep); apk_blob_pull_dep(&b, db, &dep);
...@@ -116,12 +115,6 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) ...@@ -116,12 +115,6 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
argv[i]); argv[i]);
return -1; return -1;
} }
tag = &db->repo_tags[dep.repository_tag];
if (!tag->allowed_repos) {
apk_error("Repository tag '" BLOB_FMT "' is not defined",
BLOB_PRINTF(*tag->name));
return -1;
}
} }
if (virtpkg == NULL) { if (virtpkg == NULL) {
......
...@@ -130,7 +130,6 @@ struct apk_database { ...@@ -130,7 +130,6 @@ struct apk_database {
unsigned int local_repos; unsigned int local_repos;
int performing_self_update : 1; int performing_self_update : 1;
int permanent : 1; int permanent : 1;
int missing_tags : 1;
int compat_newfeatures : 1; int compat_newfeatures : 1;
int compat_notinstallable : 1; int compat_notinstallable : 1;
int compat_old_world : 1; int compat_old_world : 1;
...@@ -195,6 +194,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts); ...@@ -195,6 +194,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts);
void apk_db_close(struct apk_database *db); void apk_db_close(struct apk_database *db);
int apk_db_write_config(struct apk_database *db); int apk_db_write_config(struct apk_database *db);
int apk_db_permanent(struct apk_database *db); int apk_db_permanent(struct apk_database *db);
int apk_db_check_world(struct apk_database *db, struct apk_dependency_array *world);
struct apk_package_array *apk_db_get_pending_triggers(struct apk_database *db); struct apk_package_array *apk_db_get_pending_triggers(struct apk_database *db);
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);
......
...@@ -1138,7 +1138,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) ...@@ -1138,7 +1138,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
struct apk_bstream *bs; struct apk_bstream *bs;
struct statfs stfs; struct statfs stfs;
apk_blob_t blob; apk_blob_t blob;
int i, r, fd, rr = 0; int r, fd, rr = 0;
memset(db, 0, sizeof(*db)); memset(db, 0, sizeof(*db));
if (apk_flags & APK_SIMULATE) { if (apk_flags & APK_SIMULATE) {
...@@ -1315,20 +1315,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) ...@@ -1315,20 +1315,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
goto ret_r; goto ret_r;
} }
/* repository id 0 is the no-tag repo */
for (i = 0; i < db->world->num; i++) {
struct apk_dependency *dep = &db->world->item[i];
int tag = dep->repository_tag;
if (tag == 0 || db->repo_tags[tag].allowed_repos != 0)
continue;
apk_warning("The repository tag for world dependency '%s@" BLOB_FMT "' does not exist",
dep->name->name,
BLOB_PRINTF(*db->repo_tags[tag].name));
db->missing_tags = 1;
}
if (db->compat_newfeatures) { if (db->compat_newfeatures) {
apk_warning("This apk-tools is OLD! Some packages %s.", apk_warning("This apk-tools is OLD! Some packages %s.",
db->compat_notinstallable ? db->compat_notinstallable ?
...@@ -1554,6 +1540,29 @@ int apk_db_permanent(struct apk_database *db) ...@@ -1554,6 +1540,29 @@ int apk_db_permanent(struct apk_database *db)
return db->permanent; return db->permanent;
} }
int apk_db_check_world(struct apk_database *db, struct apk_dependency_array *world)
{
int i, bad = 0;
if (apk_flags & APK_FORCE)
return 0;
for (i = 0; i < world->num; i++) {
struct apk_dependency *dep = &world->item[i];
int tag = dep->repository_tag;
if (tag == 0 || db->repo_tags[tag].allowed_repos != 0)
continue;
apk_warning("The repository tag for world dependency '%s@" BLOB_FMT "' does not exist",
dep->name->name,
BLOB_PRINTF(*db->repo_tags[tag].name));
bad++;
}
return bad;
}
struct apk_package *apk_db_get_pkg(struct apk_database *db, struct apk_package *apk_db_get_pkg(struct apk_database *db,
struct apk_checksum *csum) struct apk_checksum *csum)
{ {
......
...@@ -1328,7 +1328,7 @@ int apk_solver_commit_changeset(struct apk_database *db, ...@@ -1328,7 +1328,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
struct apk_change *change; struct apk_change *change;
int i, r = 0, size_diff = 0; int i, r = 0, size_diff = 0;
if (db->missing_tags && !(apk_flags & APK_FORCE)) { if (apk_db_check_world(db, world) != 0) {
apk_error("Not committing changes due to missing repository tags. Use --force to override."); apk_error("Not committing changes due to missing repository tags. Use --force to override.");
return -1; return -1;
} }
...@@ -1478,7 +1478,7 @@ int apk_solver_commit(struct apk_database *db, ...@@ -1478,7 +1478,7 @@ int apk_solver_commit(struct apk_database *db,
struct apk_package_array *solution = NULL; struct apk_package_array *solution = NULL;
int r; int r;
if (db->missing_tags && !(apk_flags & APK_FORCE)) { if (apk_db_check_world(db, world) != 0) {
apk_error("Not committing changes due to missing repository tags. Use --force to override."); apk_error("Not committing changes due to missing repository tags. Use --force to override.");
return -1; return -1;
} }
......
...@@ -97,6 +97,11 @@ static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **arg ...@@ -97,6 +97,11 @@ static int upgrade_main(void *ctx, struct apk_database *db, int argc, char **arg
struct apk_dependency_array *world = NULL; struct apk_dependency_array *world = NULL;
int i, r; int i, r;
if (apk_db_check_world(db, db->world) != 0) {
apk_error("Not continuing with upgrade due to missing repository tags. Use --force to override.");
return -1;
}
solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags; solver_flags = APK_SOLVERF_UPGRADE | uctx->solver_flags;
if (!uctx->no_self_upgrade) { if (!uctx->no_self_upgrade) {
r = apk_do_self_upgrade(db, solver_flags); r = apk_do_self_upgrade(db, solver_flags);
......
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