Subject: Re: bug#11377: configure.am - fails to remove configure before attempting replacement

From: Eric Blake <[email-masked]>
Date: Thu, 03 May 2012 16:22:31 -0600

On 05/03/2012 04:09 PM, Ronald F. Guilmette wrote:
> 
> The only problem with the approach outlined above is that sometimes (rarely)
> some Makefiles and/or other tools used as part of a build process (e.g.
> automake) may occasionally make the assumption that every regular file
> within the current (build) tree is writable, and that thus, when one of these
> tools is about to perform some operation that will attempt to effectively
> over-write some such file, the over-write can be performed _without_ first
> deleting the file in question.

Nothing against your style of coding, but I do want to point out that
recommending anyone delete a file before rebuilding its contents is
racy.  If things crash in the middle, you can be left without the file,
or with a file with incomplete contents.  It is always better to
recommend a style of atomic changes - make your target file in a
temporary location (generally in the same directory as the destination),
then use an atomic rename() to overwrite the original file with the
updated file in one go.

> 
> I want to reemphasize what I just said.  Removing a given regular file before
> attempting some operation that is intended to fully replace the contents of
> that file is a simple and altogether reasonable precaution... 

I want to reemphasize what I just said - removing a given regular file
before rebuilding it is prone to awful surprises when your build process
is interrupted unexpectedly.  Always write to a temporary name and then
use mv to move it into place, for the best safety.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org