diff options
-rw-r--r-- | sparsify/sparsify.ml | 29 | ||||
-rw-r--r-- | sparsify/utils.ml | 10 |
2 files changed, 27 insertions, 12 deletions
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index a5f95c91..8d23b405 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -130,12 +130,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, @@ -158,12 +161,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 () -> |