diff options
author | Paul Barker <paul@paulbarker.me.uk> | 2014-02-10 07:48:35 (EST) |
---|---|---|
committer | Paul Barker <paul@paulbarker.me.uk> | 2014-02-23 15:37:19 (EST) |
commit | afe4b8c3e62594b349bd88bcf4f43b4dcbe0978d (patch) | |
tree | 46b45e67f1c96fbe3ccdf0b42561018832901b1b | |
parent | 410aebda158f8342d5111df8c2ef9161d611145c (diff) |
opkg_prepare_url_for_install: Handle force_reinstall as upgrade
The best way to handle force_reinstall is to make the reinstall look like an
upgrade - because we already have a good package upgrade path. With the new
per package force_reinstall flag this is now possible.
In opkg_prepare_url_for_install, we set the per-package force_reinstall flag for
the given package. As this function is only called for packages explicitly
specified as arguments to 'opkg install' or 'opkg_install_package', the flag
will only be applied to the indended packages.
If a package name is given which exists in a package feed then we need to cheat
a little. We lookup the package in the feed and get its local filename and then
act as if that path were given as a URL.
This function is the best place to handle the force_reinstall flag as it is
responsible for setting the package hash table up so that
pkg_hash_fetch_best_installation_candidate_by_name() returns the intended
pacakge.
The old logic in opkg_install_cmd which calls opkg_remove_cmd to remove the
previously installed package is no longer needed and is removed.
This solves issue #71 without causing a regression on issue #51.
Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
-rw-r--r-- | libopkg/opkg_cmd.c | 8 | ||||
-rw-r--r-- | libopkg/opkg_download.c | 23 |
2 files changed, 21 insertions, 10 deletions
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index b091fe5..ee82462 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -481,14 +481,6 @@ opkg_install_cmd(int argc, char **argv) char *arg; int err = 0; - if (conf->force_reinstall) { - int saved_force_depends = conf->force_depends; - conf->force_depends = 1; - (void)opkg_remove_cmd(argc, argv); - conf->force_depends = saved_force_depends; - conf->force_reinstall = 0; - } - signal(SIGINT, sigint_handler); /* diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index cda5ae8..e4cbe49 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -289,7 +289,7 @@ int opkg_prepare_url_for_install(const char *url, char **namep) { int err = 0; - pkg_t *pkg; + pkg_t *pkg, *tmp; pkg = pkg_new(); @@ -321,7 +321,22 @@ opkg_prepare_url_for_install(const char *url, char **namep) opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n", pkg->name, pkg->local_filename); pkg->provided_by_hand = 1; - + } else if (conf->force_reinstall) { + /* Reload the given package from its package file into a new package + * object. This new object can then be marked as force_reinstall and + * the reinstall should go ahead like an upgrade. + */ + tmp = pkg_hash_fetch_best_installation_candidate_by_name(url); + if (!tmp) { + opkg_msg(NOTICE, "Unknown package '%s'.\n", url); + return -1; + } + err = opkg_download_pkg(tmp, conf->tmp_dir); + if (err) + return err; + err = pkg_init_from_file(pkg, tmp->local_filename); + if (err) + return err; } else { pkg_deinit(pkg); free(pkg); @@ -331,6 +346,10 @@ opkg_prepare_url_for_install(const char *url, char **namep) pkg->dest = conf->default_dest; pkg->state_want = SW_INSTALL; pkg->state_flag |= SF_PREFER; + + if (conf->force_reinstall) + pkg->force_reinstall = 1; + hash_insert_pkg(pkg, 1); if (namep) { |