You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt-v2v/SOURCES/0050-v2v-i-ova-Fix-parsing-...

64 lines
2.2 KiB

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