Blame SOURCES/0050-v2v-i-ova-Fix-parsing-if-OVA-directory-name-has-a-tr.patch

e21fe6
From 9e52e90cf8d570516d4098584c263c9d8b76c447 Mon Sep 17 00:00:00 2001
e21fe6
From: "Richard W.M. Jones" <rjones@redhat.com>
e21fe6
Date: Tue, 25 May 2021 10:27:53 +0100
e21fe6
Subject: [PATCH] v2v: -i ova: Fix parsing if OVA directory name has a trailing
e21fe6
 "/"
e21fe6
e21fe6
If you use an OVA directory with a trailing "/" in the name, virt-v2v
e21fe6
would fail with:
e21fe6
e21fe6
virt-v2v: error: internal error: assertion failed at parse_ova.ml, line 273, char 15
e21fe6
e21fe6
The fix for this is to knock off the trailing "/" if present.
e21fe6
e21fe6
Reported-by: Xiaodai Wang
e21fe6
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1964324
e21fe6
(cherry picked from commit f8428f5eaaff6dedc54a40138f760298a7a3a965)
e21fe6
---
e21fe6
 v2v/parse_ova.ml | 18 +++++++++++++++++-
e21fe6
 1 file changed, 17 insertions(+), 1 deletion(-)
e21fe6
e21fe6
diff --git a/v2v/parse_ova.ml b/v2v/parse_ova.ml
e21fe6
index 568ac5fa..fc413d2a 100644
e21fe6
--- a/v2v/parse_ova.ml
e21fe6
+++ b/v2v/parse_ova.ml
e21fe6
@@ -57,6 +57,13 @@ and ova_type =
e21fe6
    *)
e21fe6
   | TarOptimized of string (* tarball *)
e21fe6
 
e21fe6
+let string_of_t { orig_ova; top_dir; ova_type } =
e21fe6
+  sprintf "orig_ova = %s, top_dir = %s, ova_type = %s"
e21fe6
+    orig_ova top_dir
e21fe6
+    (match ova_type with
e21fe6
+     | Directory -> "Directory"
e21fe6
+     | TarOptimized tarball -> "TarOptimized " ^ tarball)
e21fe6
+
e21fe6
 type file_ref =
e21fe6
   | LocalFile of string
e21fe6
   | TarFile of string * string
e21fe6
@@ -122,6 +129,13 @@ let rec parse_ova ova =
e21fe6
   (* Exploded path must be absolute (RHBZ#1155121). *)
e21fe6
   let top_dir = absolute_path top_dir in
e21fe6
 
e21fe6
+  (* top_dir must not end with / except if it == "/" (which is
e21fe6
+   * likely not what you want).  (RHBZ#1964324)
e21fe6
+   *)
e21fe6
+  let top_dir =
e21fe6
+    if top_dir = "/" || not (String.is_suffix top_dir "/") then top_dir
e21fe6
+    else String.sub top_dir 0 (String.length top_dir - 1) in
e21fe6
+
e21fe6
   (* If virt-v2v is running as root, and the backend is libvirt, then
e21fe6
    * we have to chmod the directory to 0755 and files to 0644
e21fe6
    * so it is readable by qemu.qemu.  This is libvirt bug RHBZ#890291.
e21fe6
@@ -136,7 +150,9 @@ let rec parse_ova ova =
e21fe6
     ignore (run_command cmd)
e21fe6
   );
e21fe6
 
e21fe6
-  { orig_ova = ova; top_dir; ova_type }
e21fe6
+  let ova = { orig_ova = ova; top_dir; ova_type } in
e21fe6
+  debug "ova: %s" (string_of_t ova);
e21fe6
+  ova
e21fe6
 
e21fe6
 (* Return true if [libvirt] supports ["json:"] pseudo-URLs and accepts the
e21fe6
  * ["raw"] driver. Function also returns true if [libvirt] backend is not
e21fe6
-- 
e21fe6
2.31.1
e21fe6