Skip to content

Commit

Permalink
Merge pull request #83 from yast/add-compare-versions
Browse files Browse the repository at this point in the history
Add compare versions
  • Loading branch information
imobachgs committed Sep 25, 2017
2 parents 2f303c7 + b363551 commit ad4e305
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings-devel-doc.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-pkg-bindings-devel-doc
Version: 4.0.0
Version: 4.0.1
Release: 0
License: GPL-2.0
Group: Documentation/HTML
Expand Down
6 changes: 6 additions & 0 deletions package/yast2-pkg-bindings.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Sep 25 10:30:05 UTC 2017 - igonzalezsosa@suse.com

- Add a CompareVersions function (related to fate#323273)
- 4.0.1

-------------------------------------------------------------------
Fri Sep 22 07:24:54 UTC 2017 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-pkg-bindings
Version: 4.0.0
Version: 4.0.1
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
16 changes: 16 additions & 0 deletions src/PkgFunctions.cc
Expand Up @@ -39,6 +39,7 @@
#include <ycp/YCPList.h>

#include <zypp/ZYppFactory.h>
#include <zypp/Edition.h>

// sleep
#include <unistd.h>
Expand Down Expand Up @@ -519,3 +520,18 @@ YCPValue PkgFunctions::ExpandedUrl(const YCPString &url)
replacedUrl.raw() = zypp::Url(url->asString()->value());
return YCPString(replacedUrl.transformed().asString());
}

/**
* @builtin CompareVersions
* @short compares rpm version strings ([epoch:]version[-release])
* @param ver1 First version to compare
* @param ver2 Second version to compare
* @return -1 if ver1 is older; 0 if they are equal; 1 if ver2 is older
* @see https://github.com/openSUSE/zypper/blob/42fe3245f32d99ebb2bf643add2964de08fac0de/src/Zypper.cc#L5294
*/
YCPInteger PkgFunctions::CompareVersions(const YCPString& ver1, const YCPString& ver2) {
zypp::Edition lhs(ver1->asString()->value());
zypp::Edition rhs(ver2->asString()->value());

return lhs.compare(rhs);
}
3 changes: 3 additions & 0 deletions src/PkgFunctions.h
Expand Up @@ -837,6 +837,9 @@ class PkgFunctions
YCPValue ResolvablePropertiesEx(const YCPString& name, const YCPSymbol& kind_r, const YCPString& version, bool dependencies);
YCPValue ResolvableSetPatches(const YCPSymbol& kind_r, bool preselect);

/* TYPEINFO: int(string, string) */
YCPInteger CompareVersions(const YCPString& ver1, const YCPString& ver2);

/**
* Constructor.
*/
Expand Down

0 comments on commit ad4e305

Please sign in to comment.