pkg: apk_deps_del helper introduced

cute-signatures
Timo Teras 2009-04-16 16:32:04 +03:00
parent 4e08c87621
commit 968dfbb8b3
3 changed files with 23 additions and 12 deletions

View File

@ -70,6 +70,8 @@ APK_ARRAY(apk_package_array, struct apk_package *);
int apk_deps_add(struct apk_dependency_array **depends, int apk_deps_add(struct apk_dependency_array **depends,
struct apk_dependency *dep); struct apk_dependency *dep);
void apk_deps_del(struct apk_dependency_array **deps,
struct apk_name *name);
void apk_deps_parse(struct apk_database *db, void apk_deps_parse(struct apk_database *db,
struct apk_dependency_array **depends, struct apk_dependency_array **depends,
apk_blob_t blob); apk_blob_t blob);

View File

@ -19,7 +19,7 @@ static int del_main(void *ctx, int argc, char **argv)
struct apk_database db; struct apk_database db;
struct apk_state *state; struct apk_state *state;
struct apk_name *name; struct apk_name *name;
int i, j, r; int i, r;
if (apk_db_open(&db, apk_root, APK_OPENF_WRITE) < 0) if (apk_db_open(&db, apk_root, APK_OPENF_WRITE) < 0)
return -1; return -1;
@ -29,18 +29,8 @@ static int del_main(void *ctx, int argc, char **argv)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
name = apk_db_get_name(&db, APK_BLOB_STR(argv[i])); name = apk_db_get_name(&db, APK_BLOB_STR(argv[i]));
/* Remove from world, so we get proper changeset */
name->flags &= ~APK_NAME_TOPLEVEL; name->flags &= ~APK_NAME_TOPLEVEL;
for (j = 0; j < db.world->num; j++) { apk_deps_del(&db.world, name);
if (strcmp(db.world->item[j].name->name,
argv[i]) == 0) {
db.world->item[j] =
db.world->item[db.world->num-1];
db.world =
apk_dependency_array_resize(db.world, db.world->num-1);
}
}
} }
state = apk_state_new(&db); state = apk_state_new(&db);

View File

@ -90,6 +90,25 @@ int apk_deps_add(struct apk_dependency_array **depends,
return 0; return 0;
} }
void apk_deps_del(struct apk_dependency_array **pdeps,
struct apk_name *name)
{
struct apk_dependency_array *deps = *pdeps;
int i;
if (deps == NULL)
return;
for (i = 0; i < deps->num; i++) {
if (deps->item[i].name != name)
continue;
deps->item[i] = deps->item[deps->num-1];
*pdeps = apk_dependency_array_resize(deps, deps->num-1);
break;
}
}
struct parse_depend_ctx { struct parse_depend_ctx {
struct apk_database *db; struct apk_database *db;
struct apk_dependency_array **depends; struct apk_dependency_array **depends;