[Libguestfs] [PATCH v7 9/9] Add a virt-builder-repository tool

Pino Toscano ptoscano at redhat.com
Fri Jul 7 08:58:51 UTC 2017


On Monday, 19 June 2017 10:48:37 CEST Cédric Bosdonnat wrote:
> +let compress_to file outdir =
> +  let outimg = outdir // (Filename.basename file) ^ ".xz" in
> +
> +  info "Compressing ...%!";
> +  let cmd = sprintf "cat \"%s\" | xz -f --best --block-size=16777216 - >\"%s\""
> +                    file outimg in
> +  if shell_command cmd <> 0 then
> +    exit 1;

This finally can now be:

  let cmd = [ "xz"; "-f"; "--best"; "--block-size=16777216"; "-c"; file ] in
  let file_flags = [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; ] in
  let outfd = Unix.openfile outimg file_flags 0o666 in
  let res = run_command cmd ~stdout_chan:outfd in
  if res <> 0 then
    error (f_"'xz' command failed");

Yes, slightly more verbose, but it avoids the shell, and the need for
proper quoting. It's also logged, and faster (since the whole data of
the disk is not read twice, once by cat, and once by xz via stdin).

Thanks,
-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170707/4fbcd704/attachment.sig>


More information about the Libguestfs mailing list