diff options
author | Paul Barker <paul@paulbarker.me.uk> | 2014-02-10 07:46:23 (EST) |
---|---|---|
committer | Paul Barker <paul@paulbarker.me.uk> | 2014-02-23 15:37:19 (EST) |
commit | 410aebda158f8342d5111df8c2ef9161d611145c (patch) | |
tree | 19079d9a3e54f8ba52eb9fe34bacf68d73a784e0 /libopkg | |
parent | ce979d274826551044f63b51b51b847454cf1367 (diff) |
pkg: Add per-package force_reinstall flag
This flag allows two package object to share the same version information but be
distinguishable from each other. It is never stored on disk or reported to the
user but is used when comparing package versions.
A new function, pkg_compare_versions_no_reinstall(), is added to compare
versions without caring about this force_reinstall flag.
Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Diffstat (limited to 'libopkg')
-rw-r--r-- | libopkg/pkg.c | 42 | ||||
-rw-r--r-- | libopkg/pkg.h | 2 |
2 files changed, 27 insertions, 17 deletions
diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 9d48576..bf39b10 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -79,6 +79,7 @@ pkg_init(pkg_t *pkg) pkg->epoch = 0; pkg->version = NULL; pkg->revision = NULL; + pkg->force_reinstall = 0; pkg->dest = NULL; pkg->src = NULL; pkg->architecture = NULL; @@ -170,6 +171,8 @@ pkg_deinit(pkg_t *pkg) /* revision shares storage with version, so don't free */ pkg->revision = NULL; + pkg->force_reinstall = 0; + /* owned by opkg_conf_t */ pkg->dest = NULL; /* owned by opkg_conf_t */ @@ -937,29 +940,34 @@ verrevcmp(const char *val, const char *ref) { } int -pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg) +pkg_compare_versions_no_reinstall(const pkg_t *pkg, const pkg_t *ref_pkg) { - int r; + int r; - if (pkg->epoch > ref_pkg->epoch) { - return 1; - } + r = pkg->epoch - ref_pkg->epoch; + if (r) + return r; - if (pkg->epoch < ref_pkg->epoch) { - return -1; - } + r = verrevcmp(pkg->version, ref_pkg->version); + if (r) + return r; - r = verrevcmp(pkg->version, ref_pkg->version); - if (r) { - return r; - } + r = verrevcmp(pkg->revision, ref_pkg->revision); + return r; +} - r = verrevcmp(pkg->revision, ref_pkg->revision); - if (r) { - return r; - } +int +pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg) +{ + int r; + + r = pkg_compare_versions_no_reinstall(pkg, ref_pkg); + if (r) + return r; - return r; + /* Compare force_reinstall flags. */ + r = pkg->force_reinstall - ref_pkg->force_reinstall; + return r; } diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 1e3dd3f..45fe890 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -123,6 +123,7 @@ struct pkg unsigned long epoch; char *version; char *revision; + int force_reinstall; pkg_src_t *src; pkg_dest_t *dest; char *architecture; @@ -203,6 +204,7 @@ int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg); char *pkg_version_str_alloc(pkg_t *pkg); int pkg_compare_versions(const pkg_t *pkg, const pkg_t *ref_pkg); +int pkg_compare_versions_no_reinstall(const pkg_t *pkg, const pkg_t *ref_pkg); int pkg_name_version_and_architecture_compare(const void *a, const void *b); int abstract_pkg_name_compare(const void *a, const void *b); |