GNU bug report logs - #11816
sort -o: error comes late if opening the outfile fails

Previous Next

Package: coreutils;

Reported by: Bernhard Voelker <mail <at> bernhard-voelker.de>

Date: Fri, 29 Jun 2012 12:00:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 11816 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11816 <at> debbugs.gnu.org, Bernhard Voelker <mail <at> bernhard-voelker.de>
Subject: Re: bug#11816: sort -o: error comes late if opening the outfile fails
Date: Sat, 30 Jun 2012 14:11:08 +0100
On 06/30/2012 12:53 PM, Paul Eggert wrote:
> 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.
> 

The race would be unlikely and
only fallback to the existing operation
of slower failure.

Though I suppose opening the file is a
more direct check and would also obviate the
need to check for writeability of the containing dir
in the case of a non existent file.

OK I'm leaning towards an early open so.

As for cleaning up an empty created file,
`sort` already has an exit_cleanup() function,
so we can unlink there.

I'm not sure it's worth tuning the in==out case TBH.

cheers,
Pádraig.




This bug report was last modified 12 years and 324 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.