summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-06-25 11:09:40 +0300
committerTimo Teras <timo.teras@iki.fi>2009-06-25 11:09:40 +0300
commit3a488564753cee51832b6824128249a99eb4613b (patch)
treec246723a247f1ead91937b89a4eef0b047d72da2 /src
parent4d04bd8a463262059d83f126e604914898de81e9 (diff)
downloadapk-tools-3a488564753cee51832b6824128249a99eb4613b.tar.bz2
apk-tools-3a488564753cee51832b6824128249a99eb4613b.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/apk_defines.h3
-rw-r--r--src/state.c23
-rw-r--r--src/upgrade.c21
3 files changed, 42 insertions, 5 deletions
diff --git a/src/apk_defines.h b/src/apk_defines.h
index ecb80d0..f530e51 100644
--- a/src/apk_defines.h
+++ b/src/apk_defines.h
@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
@@ -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); }
diff --git a/src/state.c b/src/state.c
index 5d0c074..44649de 100644
--- a/src/state.c
+++ b/src/state.c
@@ -4,7 +4,7 @@
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
- * This program is free software; you can redistribute it and/or modify it
+ * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation. See http://www.gnu.org/ for details.
*/
@@ -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;
}
diff --git a/src/upgrade.c b/src/upgrade.c
index 81a6d45..59a113d 100644
--- a/src/upgrade.c
+++ b/src/upgrade.c
@@ -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,
};