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

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