GNU bug report logs -
#6268
Suggestion: truncate should allow -r and -s options together
Previous Next
Full log
Message #20 received at 6268 <at> debbugs.gnu.org (full text, mbox):
Pádraig Brady wrote:
> Subject: [PATCH] truncate: support sizes relative to an existing file
>
> * doc/coreutils.texi (truncate invocation): Mention that --reference
> bases the --size rather than just setting it.
> * src/truncate.c (usage): Likewise. Also remove the clause
> describing --size and --reference as being mutually exclusive.
> (do_truncate): Add an extra parameter to hold the size
> of a referenced file, and use it if positive.
> (main): Pass the size of a referenced file to do_truncate().
> * tests/misc/truncate-parameters: Adjust for the new combinations.
> * NEWS: Mention the change
> Suggested by Richard W.M. Jones
Nice. Thanks!
Not new with this change, but what about --ref=non-regular-file ?
Perhaps truncate should refuse to use st_size info from
a non-regular file.
Here's a pathological example:
$ echo abcdefgh > bar
$ strace -e ftruncate ./truncate --ref=/dev/tty bar
ftruncate(3, 0) = 0
$ wc -c bar
0 bar
It's obvious that such an example is not likely in practice, but since
currently truncate's --ref uses stat, it would follow a symlink, too.
For a directory you'd get unportable and probably surprising results.
Using such a reference size deserves at least a warning.
This bug report was last modified 14 years and 359 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.