summaryrefslogtreecommitdiffstats
path: root/sparsify
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-17 14:54:48 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-17 22:41:17 +0100
commitf0fb8f32b78ff0c405d2f74f9524deb3d55cce61 (patch)
treeb47549803e03d5553480f0661404c6ea0b446fbb /sparsify
parenta4318cb7aa91af193f5c164dec9b1d7d05bb971e (diff)
downloadlibguestfs-f0fb8f32b78ff0c405d2f74f9524deb3d55cce61.tar.gz
libguestfs-f0fb8f32b78ff0c405d2f74f9524deb3d55cce61.tar.xz
libguestfs-f0fb8f32b78ff0c405d2f74f9524deb3d55cce61.zip
sparsify: Fix comma/colon and quoting in qemu-img command.
Colon characters are not allowed in qemu/qemu-img filenames. There's no way to quote them. Comma characters CAN be used. However they must be quoted (by doubling) when used in the '-o' option. Fix general quoting problems in the external command. (cherry picked from commit 8d3d5a52d2746af91f770608cce5f47462f33aba)
Diffstat (limited to 'sparsify')
-rw-r--r--sparsify/sparsify.ml29
-rw-r--r--sparsify/utils.ml10
2 files changed, 27 insertions, 12 deletions
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index a76bd5f1..cd231ee4 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -125,12 +125,15 @@ read the man page virt-sparsify(1).
else
Sys.getcwd () // indisk in
- (* Check indisk filename doesn't contain a comma (limitation of qemu-img). *)
- let contains_comma =
- try ignore (String.index indisk ','); true
- with Not_found -> false in
- if contains_comma then
- error "input filename '%s' contains a comma; qemu-img command line syntax prevents us from using such an image" indisk;
+ let contains_colon filename =
+ try ignore (String.index filename ':'); true with Not_found -> false in
+
+ (* Check filenames don't contain a colon (limitation of qemu-img). *)
+ if contains_colon indisk then
+ error "input filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" indisk;
+
+ if contains_colon outdisk then
+ error "output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image" outdisk;
indisk, outdisk, compress, convert,
debug_gc, format, ignores, machine_readable,
@@ -153,12 +156,14 @@ let overlaydisk =
(* Create it with the indisk as the backing file. *)
let cmd =
- sprintf "qemu-img create -f qcow2 -o backing_file=%s%s %s > /dev/null"
- (Filename.quote indisk)
- (match format with
- | None -> ""
- | Some fmt -> sprintf ",backing_fmt=%s" (Filename.quote fmt))
- (Filename.quote tmp) in
+ let backing_file_option =
+ sprintf "backing_file=%s%s"
+ (replace_str indisk "," ",,")
+ (match format with
+ | None -> ""
+ | Some fmt -> sprintf ",backing_fmt=%s" fmt) in
+ sprintf "qemu-img create -f qcow2 -o %s %s > /dev/null"
+ (Filename.quote backing_file_option) (Filename.quote tmp) in
if verbose then
printf "%s\n%!" cmd;
if Sys.command cmd <> 0 then
diff --git a/sparsify/utils.ml b/sparsify/utils.ml
index e34fe403..d2be12c8 100644
--- a/sparsify/utils.ml
+++ b/sparsify/utils.ml
@@ -76,6 +76,16 @@ let rec string_find s sub =
in
loop 0
+let rec replace_str s s1 s2 =
+ let len = String.length s in
+ let sublen = String.length s1 in
+ let i = string_find s s1 in
+ if i = -1 then s
+ else (
+ let s' = String.sub s 0 i in
+ let s'' = String.sub s (i+sublen) (len-i-sublen) in
+ s' ^ s2 ^ replace_str s'' s1 s2
+ )
let string_random8 =
let chars = "abcdefghijklmnopqrstuvwxyz0123456789" in
fun () ->