truncate: improve handling of non regular files
authorPádraig Brady <P@draigBrady.com>
Fri, 28 May 2010 18:25:23 +0000 (19:25 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 29 May 2010 09:45:13 +0000 (10:45 +0100)
commit200501052edde61747a16cd0af60fa925ef87bfb
treea492c23081935c681ca94757e6c64424efa7c851
parent81b7585ad19e1ee0a1a43dda44dd21f11bfd6e86
truncate: improve handling of non regular files

Previously we copied `dd` and suppressed error messages
when truncating neither regular files or shared mem objects.
This was valid for `dd`, as truncation is ancillary to copying
it may also do, but for `truncate` we should display all errors.
Also we used the st_size from non regular files which is undefined,
so we display an error when the user tries this.

* src/truncate (do_truncate):  Error when referencing the size
of non regular files or non shared memory objects.  Display all
errors returned by ftruncate().
(main): Error when referencing the size of non regular files or
non shared memory objects.  Don't suppress error messages for
any file types that can't be opened for writing.
* tests/misc/truncate-dir-fail: Check that referencing the
size of a directory is not supported.
* tests/misc/truncate-fifo: Ensure the test doesn't hang
by using the `timeout` command.  Don't test the return from
running ftruncate on the fifo as it's system dependent as
to whether this fails or not.
NEWS: Mention the change in behavior.
Reported by Jim Meyering.
NEWS
src/truncate.c
tests/misc/truncate-dir-fail
tests/misc/truncate-fifo