diff options
-rw-r--r-- | src/apk_package.h | 2 | ||||
-rw-r--r-- | src/del.c | 14 | ||||
-rw-r--r-- | src/package.c | 19 |
3 files changed, 23 insertions, 12 deletions
diff --git a/src/apk_package.h b/src/apk_package.h index 8ce7e9f..a848315 100644 --- a/src/apk_package.h +++ b/src/apk_package.h @@ -70,6 +70,8 @@ APK_ARRAY(apk_package_array, struct apk_package *); int apk_deps_add(struct apk_dependency_array **depends, 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, struct apk_dependency_array **depends, apk_blob_t blob); @@ -19,7 +19,7 @@ static int del_main(void *ctx, int argc, char **argv) struct apk_database db; struct apk_state *state; struct apk_name *name; - int i, j, r; + int i, r; if (apk_db_open(&db, apk_root, APK_OPENF_WRITE) < 0) return -1; @@ -29,18 +29,8 @@ static int del_main(void *ctx, int argc, char **argv) for (i = 0; i < argc; 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; - for (j = 0; j < db.world->num; j++) { - 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); - } - } + apk_deps_del(&db.world, name); } state = apk_state_new(&db); diff --git a/src/package.c b/src/package.c index c59ec92..f74ca4d 100644 --- a/src/package.c +++ b/src/package.c @@ -90,6 +90,25 @@ int apk_deps_add(struct apk_dependency_array **depends, 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 apk_database *db; struct apk_dependency_array **depends; |