[Libguestfs] [PATCH] customize: Add --append-line.
Pino Toscano
ptoscano at redhat.com
Fri Sep 30 15:01:23 UTC 2016
On Friday, 30 September 2016 15:04:18 CEST Richard W.M. Jones wrote:
> This appends a single line to a file, with some cleverness
> involving guessing the right line endings to use.
>
> Also adds a test.
> ---
Makes sense, just a couple of notes.
> + else (
> + (* Stat the file. We want to know it's a regular file, and
> + * also its size.
> + *)
> + let { G.st_mode = mode; st_size = size } = g#statns path in
> + if Int64.logand mode 0o170000_L <> 0o100000_L then
I guess maybe it could be better to use g#is_file and g#filesize, to
avoid having to deal at application side with the file mode got in the
appliance.
> + (* Guess the line ending from the first part of the file, else
> + * use the default for this guest type.
> + *)
> + let newline =
> + let content = g#pread path 8192 0L in
> + if String.find content "\r\n" >= 0 then "\r\n"
> + else if String.find content "\n" >= 0 then "\n"
> + else default_newline () in
Should this also check for the Mac end line ('\r')? (If so, the API
documentation should mention that too.)
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/20160930/5d85a302/attachment.sig>
More information about the Libguestfs
mailing list