GNU bug report logs - #6268
Suggestion: truncate should allow -r and -s options together

Previous Next

Package: coreutils;

Reported by: "Richard W.M. Jones" <rjones <at> redhat.com>

Date: Tue, 25 May 2010 15:42:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #20 received at 6268 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 6268 <at> debbugs.gnu.org, "Richard W.M. Jones" <rjones <at> redhat.com>
Subject: Re: 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.
> (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.