[Libguestfs] [PATCH v2 13/18] v2v: windows: Convert the Windows-related conversion modules from Str to PCRE.

Richard W.M. Jones rjones at redhat.com
Thu Sep 21 14:54:08 UTC 2017


This is all new code since the virt-v2v conversion from Perl so there
was no need to check back with the original code.

See also commit 9d920732a35d9ef1b6a33509dabbbd44123e7eda.
---
 v2v/convert_windows.ml |  4 ++--
 v2v/windows.ml         | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index ac2b8180b..fa87ed84a 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -125,6 +125,7 @@ let convert (g : G.guestfs) inspect source output rcaps =
       ) in
 
   (* Locate and retrieve all uninstallation commands for Parallels Tools *)
+  let prltools_rex = PCRE.compile "(Parallels|Virtuozzo) Tools" in
   let prltools_uninsts =
     let uninsts = ref [] in
 
@@ -146,8 +147,7 @@ let convert (g : G.guestfs) inspect source output rcaps =
                  raise Not_found;
 
                let dispname = g#hivex_value_string valueh in
-               if not (Str.string_match (Str.regexp ".*\\(Parallels\\|Virtuozzo\\) Tools.*")
-                                        dispname 0) then
+               if not (PCRE.matches prltools_rex dispname) then
                  raise Not_found;
 
                let uninstval = "UninstallString" in
diff --git a/v2v/windows.ml b/v2v/windows.ml
index 6c6ed01c7..fb68c86c9 100644
--- a/v2v/windows.ml
+++ b/v2v/windows.ml
@@ -24,12 +24,12 @@ open Common_utils
 open Utils
 
 (* Detect anti-virus (AV) software installed in Windows guests. *)
-let rex_virus     = Str.regexp_case_fold "virus" (* generic *)
-let rex_kaspersky = Str.regexp_case_fold "kaspersky"
-let rex_mcafee    = Str.regexp_case_fold "mcafee"
-let rex_norton    = Str.regexp_case_fold "norton"
-let rex_sophos    = Str.regexp_case_fold "sophos"
-let rex_avg_tech  = Str.regexp_case_fold "avg technologies" (* RHBZ#1261436 *)
+let rex_virus     = PCRE.compile ~caseless:true "virus" (* generic *)
+let rex_kaspersky = PCRE.compile ~caseless:true "kaspersky"
+let rex_mcafee    = PCRE.compile ~caseless:true "mcafee"
+let rex_norton    = PCRE.compile ~caseless:true "norton"
+let rex_sophos    = PCRE.compile ~caseless:true "sophos"
+let rex_avg_tech  = PCRE.compile ~caseless:true "avg technologies" (* RHBZ#1261436 *)
 
 let rec detect_antivirus { Types.i_type = t; i_apps = apps } =
   assert (t = "windows");
@@ -44,5 +44,4 @@ and check_app { Guestfs.app2_name = name;
   name      =~ rex_sophos    ||
   publisher =~ rex_avg_tech
 
-and (=~) str rex =
-  try ignore (Str.search_forward rex str 0); true with Not_found -> false
+and (=~) str rex = PCRE.matches rex str
-- 
2.13.2




More information about the Libguestfs mailing list