[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH] customize: Add --append-line.



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

Attachment: signature.asc
Description: This is a digitally signed message part.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]