On Tue, Dec 21, 2021 at 12:12 PM Paul Eggert <[email protected]> wrote: > On 12/21/21 11:50, Jim Meyering wrote: > > One must delete $@ and the potential $@-t temporary file in any rule > > that creates a generated file and marks it (as I prefer always to do) as > > read-only by using chmod to subtract write permissions. > > > > Otherwise, the attempt to redirect to $@-t (when it is read-only) will fail. > > Gnulib isn't doing a chmod -w so that shouldn't be an issue here. > > Quite possibly Gnulib's 'rm -f $@' got copied from earlier recipes that > did 'chmod -w' for the reason you mention. > > If we were going to do a 'chmod -w' then we could do "create $@-t; chmod > a-w $@-t; mv -f $@-t $@' which (though not perfect) would be good > enough. Perhaps we didn't do that long ago in coreutils etc. because 'mv > -f' wasn't universal way back then? It's safe to assume 'mv -f' > nowadays, though.
[Assuming "create $@-t" may redirect to that file,] Even with `mv -f` support, one must still either remove $@-t or otherwise ensure that it is writable. The read-only temporary may have been left behind from a preceding, interrupted run of the same rule.
