pkg: dependencies to specific package checksum

When package is installed from commandline, we should always
install that specific instance of package (never favor repository
version if it has difference identity). Otherwise we might not
always end-up installing the .apk given on command line. The
dependency is now against specific checksum identity (marked
with >< dependency comparison). Fixes #492.
cute-signatures
Timo Teräs 2011-01-01 16:58:58 +02:00
parent 6582676150
commit 1c7e8d2617
7 changed files with 48 additions and 29 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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));
}

View File

@ -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;

View File

@ -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 "?";
}