bug#11816: sort -o: error comes late if opening the outfile fails
From:
Paul Eggert
Subject:
bug#11816: sort -o: error comes late if opening the outfile fails
Date:
Sat, 30 Jun 2012 06:53:06 -0500
User-agent:
Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
On 06/29/2012 07:55 AM, PƔdraig Brady wrote:
> Also the in==out case, you'd like to check for write-ability too.
>
> Both cases could be handled I think with something like:
>
> if (access (outfile, W_OK) != 0 && errno != ENOENT)
> error (...);
Wouldn't it be better to actually open the output file,
but not truncate it? We can then truncate it just before
actually writing to the file. That would avoid a race
condition or two.
In the in==out case, we could tune this by opening
the file just once, with O_RDWR. If the file is not
a regular file, we might have to give up and open such
a file twice, but that should be rare.