bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk - 'inplace' feature ignores file's access flags (rea


From: Andrew J. Schorr
Subject: Re: [bug-gawk] gawk - 'inplace' feature ignores file's access flags (read-only)
Date: Wed, 10 Jun 2015 10:43:11 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

On Wed, Jun 10, 2015 at 04:28:16PM +0200, Johannes Meixner wrote:
> Off the top of my head without looking at the source code
> I think 'inplace' features actually create the file anew
> i.e. the tools do not work on the existing file but remove
> (perhaps first move and finally remove) the existing file
> and write the output to a new file with same name.

Hmmm.  I don't think there's any need to look at the source code.  The
documentation is quite explicit:

https://www.gnu.org/software/gawk/manual/html_node/Extension-Sample-Inplace.html

      For each regular file that is processed, the extension redirects
   standard output to a temporary file configured to have the same owner
   and permissions as the original.  After the file has been processed,
   the extension restores standard output to its original destination.  If
   `INPLACE_SUFFIX' is not an empty string, the original file is linked to
   a backup file name created by appending that suffix.  Finally, the
   temporary file is renamed to the original file name.

I think your bash examples are not comparable.  The sequence of events
is approximately like this:

   gawk '<awk program>' <input file> > <temporary file>
   chown <owner>:<group> <temporary file>
   chmod <perms> <temporary file>
   if [ -n "$INPLACE_SUFFIX" ]; then
      rm -f <input file>$INPLACE_SUFFIX
      ln <input file> <input file>$INPLACE_SUFFIX
   fi
   mv <temporary file> <input file>

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]