sort: avoid redundant processing with inaccessible inputs or output
authorPádraig Brady <P@draigBrady.com>
Sun, 1 Jul 2012 00:14:42 +0000 (01:14 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 2 Jul 2012 19:14:29 +0000 (21:14 +0200)
commit44fbd3fd862e34d42006f8b74cb11c9c56346417
tree2455d37347b3e504d30c33c607cd1f096c9c51c5
parent8285c2aca0ee81ca2ce0507084259de8384e809f
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 accessibility of
inputs and output, before processing starts.
* tests/misc/sort: Adjust to the changed error message.
* tests/misc/sort-merge-fdlimit: Account for the earlier opened
file descriptor of the specified output file.
* tests/misc/sort-exit-early: A new test to exercise the improvements.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the improvement.

Suggested-by: Bernhard Voelker
NEWS
src/sort.c
tests/Makefile.am
tests/misc/sort
tests/misc/sort-exit-early [new file with mode: 0755]
tests/misc/sort-merge-fdlimit