summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apk_package.h3
-rw-r--r--src/apk_version.h1
-rw-r--r--src/del.c3
-rw-r--r--src/package.c24
-rw-r--r--src/solver.c10
5 files changed, 21 insertions, 20 deletions
diff --git a/src/apk_package.h b/src/apk_package.h
index 41d65cb..c68fef7 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -59,7 +59,8 @@ struct apk_sign_ctx {
struct apk_dependency {
struct apk_name *name;
apk_blob_t *version;
- int result_mask;
+ unsigned optional : 1;
+ unsigned result_mask : 3;
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);
diff --git a/src/apk_version.h b/src/apk_version.h
index 8c264e6..514fea9 100644
--- a/src/apk_version.h
+++ b/src/apk_version.h
@@ -21,7 +21,6 @@
#define APK_DEPMASK_REQUIRE (APK_VERSION_EQUAL|APK_VERSION_LESS|\
APK_VERSION_GREATER)
#define APK_DEPMASK_CHECKSUM (APK_VERSION_LESS|APK_VERSION_GREATER)
-#define APK_DEPMASK_CONFLICT (0)
const char *apk_version_op_string(int result_mask);
int apk_version_result_mask(const char *str);
diff --git a/src/del.c b/src/del.c
index 3d7ffe7..ffa924f 100644
--- a/src/del.c
+++ b/src/del.c
@@ -58,8 +58,7 @@ static void foreach_installed_reverse_dependency(
for (k = 0; k < pkg0->depends->num; k++) {
struct apk_dependency *dep = &pkg0->depends->item[k];
if (dep->name == name &&
- (dep->result_mask == APK_DEPMASK_CONFLICT ||
- apk_dep_is_satisfied(dep, pkg)))
+ apk_dep_is_satisfied(dep, pkg))
break;
}
if (k >= pkg0->depends->num)
diff --git a/src/package.c b/src/package.c
index cc4c141..3886d82 100644
--- a/src/package.c
+++ b/src/package.c
@@ -195,16 +195,16 @@ void apk_blob_pull_dep(apk_blob_t *b, struct apk_database *db, struct apk_depend
{
struct apk_name *name;
apk_blob_t bname, bop, bver = APK_BLOB_NULL;
- int mask = APK_DEPMASK_REQUIRE;
+ int mask = APK_DEPMASK_REQUIRE, optional = 0;
size_t len;
/* [!]name[<,<=,=,>=,>]ver */
if (APK_BLOB_IS_NULL(*b))
goto fail;
if (b->ptr[0] == '!') {
- mask = 0;
b->ptr++;
b->len--;
+ optional = 1;
}
if (apk_blob_cspn(*b, "<>= ", &bname, &bop)) {
int i;
@@ -243,10 +243,14 @@ void apk_blob_pull_dep(apk_blob_t *b, struct apk_database *db, struct apk_depend
if (name == NULL)
goto fail;
+ if (optional)
+ mask ^= APK_DEPMASK_REQUIRE;
+
*dep = (struct apk_dependency){
.name = name,
.version = apk_blob_atomize_dup(bver),
.result_mask = mask,
+ .optional = optional,
};
return;
fail:
@@ -292,11 +296,8 @@ static int parse_depend(void *ctx, apk_blob_t blob)
int apk_dep_is_satisfied(struct apk_dependency *dep, struct apk_package *pkg)
{
- if (pkg == NULL) {
- if (dep->result_mask == APK_DEPMASK_CONFLICT)
- return 1;
- return 0;
- }
+ if (pkg == NULL)
+ return dep->optional;
if (dep->name != pkg->name)
return 0;
if (dep->result_mask == APK_DEPMASK_CHECKSUM) {
@@ -326,13 +327,16 @@ void apk_blob_pull_deps(apk_blob_t *b, struct apk_database *db, struct apk_depen
void apk_blob_push_dep(apk_blob_t *to, struct apk_dependency *dep)
{
- if (dep->result_mask == APK_DEPMASK_CONFLICT)
+ int result_mask = dep->result_mask;
+
+ if (dep->optional) {
apk_blob_push_blob(to, APK_BLOB_PTR_LEN("!", 1));
+ result_mask ^= APK_DEPMASK_REQUIRE;
+ }
apk_blob_push_blob(to, APK_BLOB_STR(dep->name->name));
- if (dep->result_mask != APK_DEPMASK_CONFLICT &&
- dep->result_mask != APK_DEPMASK_REQUIRE) {
+ if (!APK_BLOB_IS_NULL(*dep->version)) {
apk_blob_push_blob(to, APK_BLOB_STR(apk_version_op_string(dep->result_mask)));
apk_blob_push_blob(to, *dep->version);
}
diff --git a/src/solver.c b/src/solver.c
index 49cfc79..d277bc5 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -126,8 +126,7 @@ static void foreach_dependency_pkg(
struct apk_package *pkg0 = name0->pkgs->item[j];
/* conflict depends on all to be not installed */
- if (dep->result_mask != APK_DEPMASK_CONFLICT &&
- !apk_dep_is_satisfied(dep, pkg0))
+ if (!apk_dep_is_satisfied(dep, pkg0))
continue;
cb(ss, pkg0);
@@ -154,8 +153,7 @@ static void foreach_rinstall_if_pkg(
for (k = 0; k < pkg0->install_if->num; k++) {
struct apk_dependency *dep = &pkg0->install_if->item[k];
if (dep->name == name &&
- (dep->result_mask == APK_DEPMASK_CONFLICT ||
- apk_dep_is_satisfied(dep, pkg)))
+ apk_dep_is_satisfied(dep, pkg))
break;
}
if (k >= pkg0->install_if->num)
@@ -635,7 +633,7 @@ static void apply_constraint(struct apk_solver_state *ss, struct apk_dependency
if (ss->latest_decision != NULL)
inherit_name_state(name, ss->latest_decision->name);
- if (dep->result_mask != APK_DEPMASK_CONFLICT)
+ if (!dep->optional)
ns->requirers++;
update_name_state(ss, name);
}
@@ -675,7 +673,7 @@ static void undo_constraint(struct apk_solver_state *ss, struct apk_dependency *
if (ss->latest_decision && has_inherited_state(ss->latest_decision->name))
recalculate_inherted_name_state(name);
- if (dep->result_mask != APK_DEPMASK_CONFLICT)
+ if (!dep->optional)
ns->requirers--;
update_name_state(ss, name);
}