On Mon, Nov 24, 2014 at 03:52:26PM +0100, Pino Toscano wrote:
Bind and use rpmvercmp to compare versions of packages when sorting
them, instead of an own string-based comparison function.
---
src/librpm-c.c | 12 ++++++++++++
src/librpm.ml | 1 +
src/librpm.mli | 1 +
src/rpm.ml | 2 +-
4 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/librpm-c.c b/src/librpm-c.c
index 1ae3bad..fc847d6 100644
--- a/src/librpm-c.c
+++ b/src/librpm-c.c
@@ -122,6 +122,12 @@ supermin_rpm_version (value unit)
}
value
+supermin_rpm_vercmp (value av, value bv)
+{
+ return Val_int (rpmvercmp (String_val (av), String_val (bv)));
+}
+
+value
supermin_rpm_open (value debugv)
{
CAMLparam1 (debugv);
@@ -445,6 +451,12 @@ supermin_rpm_version (value unit)
}
value
+supermin_rpm_vercmp (value av, value bv)
+{
+ abort ();
+}
+
+value
supermin_rpm_open (value debugv)
{
abort ();
diff --git a/src/librpm.ml b/src/librpm.ml
index aa8d367..8c30248 100644
--- a/src/librpm.ml
+++ b/src/librpm.ml
@@ -19,6 +19,7 @@
external rpm_is_available : unit -> bool = "supermin_rpm_is_available"
external rpm_version : unit -> string = "supermin_rpm_version"
+external rpm_vercmp : string -> string -> int = "supermin_rpm_vercmp"
Small detail:
This is a "noalloc" function, so you can make it a bit faster:
http://camltastic.blogspot.co.uk/2008/08/tip-calling-c-functions-directly...
ACK.
Rich.
type t
diff --git a/src/librpm.mli b/src/librpm.mli
index 880a038..da73911 100644
--- a/src/librpm.mli
+++ b/src/librpm.mli
@@ -19,6 +19,7 @@
val rpm_is_available : unit -> bool
val rpm_version : unit -> string
+val rpm_vercmp : string -> string -> int
type t
diff --git a/src/rpm.ml b/src/rpm.ml
index 640a02a..ce803e1 100644
--- a/src/rpm.ml
+++ b/src/rpm.ml
@@ -144,7 +144,7 @@ let rpm_package_of_string str =
* architecture.
*)
let cmp { version = v1; arch = a1 } { version = v2; arch = a2 } =
- let i = compare_version v2 v1 in
+ let i = rpm_vercmp v2 v1 in
if i <> 0 then i
else compare_architecture a2 a1
in
--
1.9.3
_______________________________________________
Libguestfs mailing list
Libguestfs(a)redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v