bug#6268: Suggestion: truncate should allow -r and -s options together (original) (raw)

[Top][All Lists]


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Jim Meyering
Subject: bug#6268: Suggestion: truncate should allow -r and -s options together
Date: Fri, 28 May 2010 09:59:39 +0200

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. (dotruncate): 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 dotruncate(). * 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.