On Fri, Sep 30, 2016 at 05:01:23PM +0200, Pino Toscano wrote:
 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. 
These hard-coded constants aren't really a problem.  It's what the
guestfs_statns ABI defines.  We also use them in cat/visit.c.
 > +    (* 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.) 
OK I added that, retested it, and pushed it.
Rich.
-- 
Richard Jones, Virtualization Group, Red Hat 
http://people.redhat.com/~rjones
Read my programming and virtualization blog: 
http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  
http://libguestfs.org