Subject: bug#11816: sort -o: error comes late if opening the outfile fails

From: Jim Meyering <[email-masked]>
Date: Mon, 02 Jul 2012 13:26:46 +0200

Pádraig Brady wrote:
...
> Subject: [PATCH] sort: avoid redundant processing with inaccessible inputs or
>  output
>
> * src/sort.c (check_inputs): A new function to verify all inputs
> are accessible before further processing.
> (check_output): A new function to open or create a specified
> output file, before futher processing.
> (stream_open): Adjust to truncating the previously opened
> output file rather than opening directly.
> (avoid_trashing_input): Optimize to stat the output file
> descriptor, rather than the file name.
> (main): Call the new functions to check accessability of

Hi Pádraig,

Thanks for dealing with this.
So far, I've read through the commit log and NEWS:

s/accessability/accessibility/

> inputs and output, before processing starts.
...
> diff --git a/NEWS b/NEWS
> index 8c75a32..c51fb78 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -41,6 +41,12 @@ GNU coreutils NEWS                                    -*- outline -*-
>    patches as well as enough support to build on the Hurd, we no longer
>    have any reason to include it here.
>
> +** Improvements
> +
> +  sort will avoid redundant processing in the presence of inaccessible inputs,

s/will avoid/avoids/ (or "now avoids") ?

> +  or unwritable output.  Immediate errors are now given before any potentially
> +  expensive processing is initiated.

Maybe replace that "Immediate ..." sentence with something like this:

  Sort now diagnoses certain errors at start-up, rather than
  only after potentially expensive processing.