[Pkg-libvirt-commits] [libguestfs] 222/384: mllib: Add function for comparing LVM2 UUIDs, ignoring '-' characters.

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 16:57:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 7d784fb9c90038e94761d9ea928b1c12d62625e9
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jan 28 14:18:48 2015 +0000

    mllib: Add function for comparing LVM2 UUIDs, ignoring '-' characters.
---
 mllib/common_utils.ml  | 21 +++++++++++++++++++++
 mllib/common_utils.mli |  3 +++
 2 files changed, 24 insertions(+)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index d4994cf..898be17 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -506,6 +506,27 @@ let compare_version v1 v2 =
   in
   compare (split_version v1) (split_version v2)
 
+(* Annoying LVM2 returns a differing UUID strings for different
+ * function calls (sometimes containing or not containing '-'
+ * characters), so we have to normalize each string before
+ * comparison.  c.f. 'compare_pvuuids' in virt-filesystem.
+ *)
+let compare_lvm2_uuids uuid1 uuid2 =
+  let n1 = String.length uuid1 and n2 = String.length uuid2 in
+  let rec loop i1 i2 =
+    if i1 = n1 && i2 = n2 then 0            (* matching *)
+    else if i1 >= n1 then 1                 (* different lengths *)
+    else if i2 >= n2 then -1
+    else if uuid1.[i1] = '-' then loop (i1+1) i2 (* ignore '-' characters *)
+    else if uuid2.[i2] = '-' then loop i1 (i2+1)
+    else (
+      let c = compare uuid1.[i1] uuid2.[i2] in
+      if c <> 0 then c                          (* not matching *)
+      else loop (i1+1) (i2+1)
+    )
+  in
+  loop 0 0
+
 (* Run an external command, slurp up the output as a list of lines. *)
 let external_command ~prog cmd =
   let chan = Unix.open_process_in cmd in
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index ccb2e5f..5d3149a 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -106,6 +106,9 @@ val display_long_options : unit -> 'a
 val compare_version : string -> string -> int
 (** Compare two version strings. *)
 
+val compare_lvm2_uuids : string -> string -> int
+(** Compare two LVM2 UUIDs, ignoring '-' characters. *)
+
 val external_command : prog:string -> string -> string list
 (** Run an external command, slurp up the output as a list of lines. *)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list