diff options
author | Pádraig Brady <P@draigBrady.com> | 2010-05-28 19:25:23 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2010-05-29 10:45:13 +0100 |
commit | 200501052edde61747a16cd0af60fa925ef87bfb (patch) | |
tree | a492c23081935c681ca94757e6c64424efa7c851 /tests | |
parent | 81b7585ad19e1ee0a1a43dda44dd21f11bfd6e86 (diff) | |
download | coreutils-200501052edde61747a16cd0af60fa925ef87bfb.tar.xz |
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.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/misc/truncate-dir-fail | 3 | ||||
-rwxr-xr-x | tests/misc/truncate-fifo | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/tests/misc/truncate-dir-fail b/tests/misc/truncate-dir-fail index d2ecf2fe6..fe33857a2 100755 --- a/tests/misc/truncate-dir-fail +++ b/tests/misc/truncate-dir-fail @@ -26,4 +26,7 @@ fi # truncate on dir not allowed truncate -s+0 . && fail=1 +# getting the size of a dir is not allowed +truncate -r. file && fail=1 + Exit $fail diff --git a/tests/misc/truncate-fifo b/tests/misc/truncate-fifo index 8e2276dab..a4c36cb90 100755 --- a/tests/misc/truncate-fifo +++ b/tests/misc/truncate-fifo @@ -1,5 +1,5 @@ #!/bin/sh -# Make sure truncate works on fifos without hanging or errors +# Make sure truncate works on fifos without hanging # Copyright (C) 2008-2010 Free Software Foundation, Inc. @@ -23,9 +23,9 @@ fi . $srcdir/test-lib.sh -mkfifo_or_skip_ "fifo" +mkfifo_or_skip_ fifo - -truncate -s0 "fifo" || fail=1 +timeout 10 truncate -s0 fifo +test "$?" = 124 && fail=1 Exit $fail |