summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/apk_package.h5
-rw-r--r--src/apk_version.h5
-rw-r--r--src/info.c3
-rw-r--r--src/package.c36
-rw-r--r--src/search.c3
-rw-r--r--src/state.c23
-rw-r--r--src/version.c2
7 files changed, 48 insertions, 29 deletions
diff --git a/src/apk_package.h b/src/apk_package.h
index 65d20ad..3e50979 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -56,10 +56,6 @@ struct apk_sign_ctx {
} signature;
};
-#define APK_DEPMASK_REQUIRE (APK_VERSION_EQUAL|APK_VERSION_LESS|\
- APK_VERSION_GREATER)
-#define APK_DEPMASK_CONFLICT (0)
-
struct apk_dependency {
struct apk_name *name;
apk_blob_t *version;
@@ -114,6 +110,7 @@ int apk_dep_from_blob(struct apk_dependency *dep, struct apk_database *db,
apk_blob_t blob);
void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
struct apk_package *pkg);
+int apk_dep_is_satisfied(struct apk_dependency *dep, struct apk_package *pkg);
void apk_blob_push_dep(apk_blob_t *to, struct apk_dependency *dep);
int apk_deps_add(struct apk_dependency_array **depends,
diff --git a/src/apk_version.h b/src/apk_version.h
index ea3f444..42df3b9 100644
--- a/src/apk_version.h
+++ b/src/apk_version.h
@@ -18,6 +18,11 @@
#define APK_VERSION_LESS 2
#define APK_VERSION_GREATER 4
+#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);
int apk_version_validate(apk_blob_t ver);
diff --git a/src/info.c b/src/info.c
index 1b936f0..c9dc39c 100644
--- a/src/info.c
+++ b/src/info.c
@@ -84,8 +84,7 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
if (j >= name->pkgs->num)
continue;
- if (!(apk_version_compare_blob(*pkg->version, *dep.version)
- & dep.result_mask))
+ if (!apk_dep_is_satisfied(&dep, pkg))
continue;
verbose_print_pkg(pkg, 0);
diff --git a/src/package.c b/src/package.c
index dfd9cc9..37e4357 100644
--- a/src/package.c
+++ b/src/package.c
@@ -222,11 +222,8 @@ int apk_dep_from_blob(struct apk_dependency *dep, struct apk_database *db,
break;
}
}
- if ((mask & (APK_VERSION_LESS|APK_VERSION_GREATER))
- == (APK_VERSION_LESS|APK_VERSION_GREATER))
- return -EINVAL;
-
- if (!apk_version_validate(bver))
+ if ((mask & APK_DEPMASK_CHECKSUM) != APK_DEPMASK_CHECKSUM &&
+ !apk_version_validate(bver))
return -EINVAL;
blob = bname;
@@ -247,10 +244,16 @@ int apk_dep_from_blob(struct apk_dependency *dep, struct apk_database *db,
void apk_dep_from_pkg(struct apk_dependency *dep, struct apk_database *db,
struct apk_package *pkg)
{
+ char buf[64];
+ apk_blob_t b = APK_BLOB_BUF(buf);
+
+ apk_blob_push_csum(&b, &pkg->csum);
+ b = apk_blob_pushed(APK_BLOB_BUF(buf), b);
+
*dep = (struct apk_dependency) {
.name = pkg->name,
- .version = pkg->version,
- .result_mask = APK_VERSION_EQUAL,
+ .version = apk_blob_atomize_dup(b),
+ .result_mask = APK_DEPMASK_CHECKSUM,
};
}
@@ -273,6 +276,25 @@ static int parse_depend(void *ctx, apk_blob_t blob)
return 0;
}
+int apk_dep_is_satisfied(struct apk_dependency *dep, struct apk_package *pkg)
+{
+ if (dep->name != pkg->name)
+ return 0;
+ if (dep->result_mask == APK_DEPMASK_CHECKSUM) {
+ struct apk_checksum csum;
+ apk_blob_t b = *dep->version;
+
+ apk_blob_pull_csum(&b, &csum);
+ if (apk_checksum_compare(&csum, &pkg->csum) == 0)
+ return 1;
+ } else {
+ if (apk_version_compare_blob(*pkg->version, *dep->version)
+ & dep->result_mask)
+ return 1;
+ }
+ return 0;
+}
+
void apk_deps_parse(struct apk_database *db,
struct apk_dependency_array **depends,
apk_blob_t blob)
diff --git a/src/search.c b/src/search.c
index cb8c44d..3973552 100644
--- a/src/search.c
+++ b/src/search.c
@@ -53,8 +53,7 @@ static int print_rdepends(struct apk_package *pkg)
for (k = 0; k < pkg0->depends->num; k++) {
dep = &pkg0->depends->item[k];
if (name == dep->name &&
- (apk_version_compare_blob(*pkg->version, *dep->version)
- & dep->result_mask)) {
+ apk_dep_is_satisfied(dep, pkg)) {
printf(" " PKG_VER_FMT,
PKG_VER_PRINTF(pkg0));
}
diff --git a/src/state.c b/src/state.c
index ddfca57..408df72 100644
--- a/src/state.c
+++ b/src/state.c
@@ -130,8 +130,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db,
continue;
for (j = 0; j < nc->num; ) {
- if (apk_version_compare_blob(*nc->pkgs[j]->version, *dep->version)
- & dep->result_mask) {
+ if (apk_dep_is_satisfied(dep, nc->pkgs[j])) {
j++;
} else {
nc->pkgs[j] = nc->pkgs[nc->num - 1];
@@ -286,8 +285,7 @@ int apk_state_prune_dependency(struct apk_state *state,
return -1;
}
} else {
- if (!(apk_version_compare_blob(*pkg->version, *dep->version)
- & dep->result_mask))
+ if (!apk_dep_is_satisfied(dep, pkg))
return -1;
}
@@ -301,9 +299,8 @@ int apk_state_prune_dependency(struct apk_state *state,
c = ns_to_choices(state->name[name->id]);
i = 0;
while (i < c->num) {
- if (apk_version_compare_blob(*c->pkgs[i]->version, *dep->version)
- & dep->result_mask) {
- i++;
+ if (apk_dep_is_satisfied(dep, c->pkgs[i])) {
+ i++;
continue;
}
@@ -444,8 +441,7 @@ static int call_if_dependency_broke(struct apk_state *state,
dep->result_mask == APK_DEPMASK_CONFLICT)
continue;
if (dep_pkg != NULL &&
- (apk_version_compare_blob(*dep_pkg->version, *dep->version)
- & dep->result_mask))
+ apk_dep_is_satisfied(dep, dep_pkg))
continue;
return cb(state, pkg, dep, ctx);
}
@@ -619,12 +615,11 @@ static void apk_print_change(struct apk_database *db,
msg = "Downgrading";
break;
case APK_VERSION_EQUAL:
- if (newpkg == oldpkg) {
+ if (newpkg == oldpkg)
msg = "Re-installing";
- break;
- }
- /* fallthrough - equal version, but different
- * package is counted as upgrade */
+ else
+ msg = "Replacing";
+ break;
case APK_VERSION_GREATER:
msg = "Upgrading";
break;
diff --git a/src/version.c b/src/version.c
index 34c5f1a..2de886a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -151,6 +151,8 @@ const char *apk_version_op_string(int mask)
return ">=";
case APK_VERSION_GREATER:
return ">";
+ case APK_DEPMASK_CHECKSUM:
+ return "><";
default:
return "?";
}