Commit 3a488564 authored by Timo Teräs's avatar Timo Teräs

upgrade: add --available option

That will make the upgrade prefer packages available in repositories.
This is good if one want's to downgrade packages by removing an experimental
repository. Or to force re-install of locally built vs. repository version
when the package version are same, but checksum is different. Fixes #51.
parent 4d04bd8a
......@@ -59,6 +59,7 @@ extern unsigned int apk_flags;
#define APK_PROGRESS 0x0008
#define APK_UPGRADE 0x0010
#define APK_RECURSIVE 0x0020
#define APK_PREFER_AVAILABLE 0x0040
#define apk_error(args...) apk_log("ERROR: ", args);
#define apk_warning(args...) if (apk_verbosity > 0) { apk_log("WARNING: ", args); }
......
......@@ -232,8 +232,25 @@ int apk_state_lock_dependency(struct apk_state *state,
if (apk_pkg_get_state(c->pkgs[i]) == APK_PKG_INSTALLED)
installed = pkg;
if (latest == NULL ||
apk_pkg_version_compare(pkg, latest) == APK_VERSION_GREATER)
if (latest == NULL) {
latest = pkg;
continue;
}
if (apk_flags & APK_PREFER_AVAILABLE) {
if (latest->repos != 0 && pkg->repos == 0)
continue;
if (latest->repos == 0 && pkg->repos != 0) {
latest = pkg;
continue;
}
/* Otherwise both are not available, or both are
* available and we just compare the versions then */
}
if (apk_pkg_version_compare(pkg, latest) == APK_VERSION_GREATER)
latest = pkg;
}
......
......@@ -16,6 +16,18 @@
#include "apk_database.h"
#include "apk_state.h"
static int upgrade_parse(void *ctx, int optch, int optindex, const char *optarg)
{
switch (optch) {
case 'a':
apk_flags |= APK_PREFER_AVAILABLE;
break;
default:
return -1;
}
return 0;
}
static int upgrade_main(void *ctx, int argc, char **argv)
{
struct apk_database db;
......@@ -45,9 +57,16 @@ err:
return r;
}
static struct option upgrade_options[] = {
{ "available", no_argument, NULL, 'a' },
};
static struct apk_applet apk_upgrade = {
.name = "upgrade",
.usage = "",
.usage = "[-a|--available]",
.num_options = ARRAY_SIZE(upgrade_options),
.options = upgrade_options,
.parse = upgrade_parse,
.main = upgrade_main,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment