|
|
ffd6ed |
From 851928b06c6b61dca845c971e80e8e0a85ef9482 Mon Sep 17 00:00:00 2001
|
|
|
ffd6ed |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
ffd6ed |
Date: Tue, 1 Sep 2015 14:56:10 +0100
|
|
|
ffd6ed |
Subject: [PATCH] v2v: Fix handling of extra slashes in dcPath calculation
|
|
|
ffd6ed |
(RHBZ#1258342).
|
|
|
ffd6ed |
|
|
|
ffd6ed |
This updates commit 20f1eb400b13be8733b6586769c4845b99a70722.
|
|
|
ffd6ed |
|
|
|
ffd6ed |
Thanks: Tingting Zheng
|
|
|
ffd6ed |
(cherry picked from commit 51bc573d0c4e78104a682e7c42d63d701aedd093)
|
|
|
ffd6ed |
---
|
|
|
ffd6ed |
v2v/input_libvirt_vcenter_https.ml | 19 +++++++++++++++++--
|
|
|
ffd6ed |
1 file changed, 17 insertions(+), 2 deletions(-)
|
|
|
ffd6ed |
|
|
|
ffd6ed |
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
|
|
|
ffd6ed |
index 295dded..dd02feb 100644
|
|
|
ffd6ed |
--- a/v2v/input_libvirt_vcenter_https.ml
|
|
|
ffd6ed |
+++ b/v2v/input_libvirt_vcenter_https.ml
|
|
|
ffd6ed |
@@ -170,6 +170,8 @@ and run_curl_get_lines curl_args =
|
|
|
ffd6ed |
Unix.unlink config_file;
|
|
|
ffd6ed |
lines
|
|
|
ffd6ed |
|
|
|
ffd6ed |
+let multiple_slash = Str.regexp "/+"
|
|
|
ffd6ed |
+
|
|
|
ffd6ed |
(* Helper function to extract the dcPath from a URI. *)
|
|
|
ffd6ed |
let get_dcPath uri scheme =
|
|
|
ffd6ed |
let default_dc = "ha-datacenter" in
|
|
|
ffd6ed |
@@ -183,6 +185,10 @@ let get_dcPath uri scheme =
|
|
|
ffd6ed |
(* vCenter: URIs are *usually* '/Folder/Datacenter/esxi' so we can
|
|
|
ffd6ed |
* just chop off the first '/' and final '/esxi' to get the dcPath.
|
|
|
ffd6ed |
*
|
|
|
ffd6ed |
+ * The libvirt driver allows things like '/DC///esxi////' so we also
|
|
|
ffd6ed |
+ * have to handle trailing slashes and collapse multiple slashes into
|
|
|
ffd6ed |
+ * single (RHBZ#1258342).
|
|
|
ffd6ed |
+ *
|
|
|
ffd6ed |
* However if there is a cluster involved then the URI may be
|
|
|
ffd6ed |
* /Folder/Datacenter/Cluster/esxi but dcPath=Folder/Datacenter/Cluster
|
|
|
ffd6ed |
* won't work. In this case the user has to adjust the path to
|
|
|
ffd6ed |
@@ -190,12 +196,21 @@ let get_dcPath uri scheme =
|
|
|
ffd6ed |
* should be a way to ask the libvirt vpx driver for the correct
|
|
|
ffd6ed |
* path, but there isn't. XXX See also RHBZ#1256823.
|
|
|
ffd6ed |
*)
|
|
|
ffd6ed |
- let path = (* chop off the first '/' *)
|
|
|
ffd6ed |
+ (* Collapse multiple slashes to single slash. *)
|
|
|
ffd6ed |
+ let path = Str.global_replace multiple_slash "/" path in
|
|
|
ffd6ed |
+ (* Chop off the first and trailing '/' (if found). *)
|
|
|
ffd6ed |
+ let path =
|
|
|
ffd6ed |
let len = String.length path in
|
|
|
ffd6ed |
if len > 0 && path.[0] = '/' then
|
|
|
ffd6ed |
String.sub path 1 (len-1)
|
|
|
ffd6ed |
else path in
|
|
|
ffd6ed |
- let len = (* chop off the final element (ESXi hostname) *)
|
|
|
ffd6ed |
+ let path =
|
|
|
ffd6ed |
+ let len = String.length path in
|
|
|
ffd6ed |
+ if len > 0 && path.[len-1] = '/' then
|
|
|
ffd6ed |
+ String.sub path 0 (len-1)
|
|
|
ffd6ed |
+ else path in
|
|
|
ffd6ed |
+ (* Chop off the final element (ESXi hostname). *)
|
|
|
ffd6ed |
+ let len =
|
|
|
ffd6ed |
try String.rindex path '/' with Not_found -> String.length path in
|
|
|
ffd6ed |
String.sub path 0 len
|
|
|
ffd6ed |
);
|
|
|
ffd6ed |
--
|
|
|
ffd6ed |
1.8.3.1
|
|
|
ffd6ed |
|