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 #23 received at 6268 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 6268 <at> debbugs.gnu.org
Subject: Re: bug#6268: Suggestion: truncate should allow -r and -s options
	together
Date: Fri, 28 May 2010 14:17:58 +0100
> 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.

Yes that's safer. st_size is only defined for regular files
(or shared mem), so I'll only allow regular files.
I'll push a separate patch soon.

Since we're only referencing the size, there is the argument
that we should be trying harder to get the size of block devices
for example.  There are portability issues with that though,
and doing outside of truncate is easy enough, so I'll leave that for now.

cheers,
Pádraig.




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.