Open p5pRT opened 18 years ago
Truncating a string isn't an expensive operation\, so is this really too much to ask?
#! /usr/local/bin/perl
use strict;
open(my $fh\,'+>'\,\my $buf)
or die "open: $!\n";
print {$fh} "Hello\, World!\n"
or die "print: $!\n";
truncate($fh\,5)
or warn "truncate: $!\n"; # outputs "truncate: Bad file
descriptor"
print 'length: '.length($buf)."\n"; # outputs "length: 14"
On 26/08/06\, via RT Bo Lindbergh \perlbug\-followup@​perl\.org wrote:
Truncating a string isn't an expensive operation\, so is this really too much to ask?
A quick look at the implementation suggests that truncate() only works for filehandles currently.
The RT System itself - Status changed from 'new' to 'open'
Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com writes:
On 26/08/06\, via RT Bo Lindbergh \perlbug\-followup@​perl\.org wrote:
Truncating a string isn't an expensive operation\, so is this really too much to ask?
A quick look at the implementation suggests that truncate() only works for filehandles currently.
But a PerlIO::Scalar "is" a file handle :-(
That said we there isn't a ftruncate() hook in PerlIO virtualization so I don't know what we do...
In article \20060901184007\.24952\.7@​llama\.ing\-simmons\.net\, nick@ing-simmons.net (Nick Ing-Simmons) wrote:
Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com writes:
On 26/08/06\, via RT Bo Lindbergh \perlbug\-followup@​perl\.org wrote:
Truncating a string isn't an expensive operation\, so is this really too much to ask?
A quick look at the implementation suggests that truncate() only works for filehandles currently.
But a PerlIO::Scalar "is" a file handle :-(
That said we there isn't a ftruncate() hook in PerlIO virtualization so I don't know what we do...
Adding _only_ ftruncate to PerlIO is not the Right Thing to do\, because the next bug report would be "Why can't you use the -s operator to get the length of the scalar used by a PerlIO::Scalar handle?" And once you have both fstat and ftruncate\, you might as well complete the set and add fchown\, fchmod\, and futimes too.
/Bo Lindbergh
Bo Lindbergh \blgl@​hagernas\.com writes:
In article \20060901184007\.24952\.7@​llama\.ing\-simmons\.net\, nick@ing-simmons.net (Nick Ing-Simmons) wrote:
Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com writes:
On 26/08/06\, via RT Bo Lindbergh \perlbug\-followup@​perl\.org wrote:
Truncating a string isn't an expensive operation\, so is this really too much to ask?
A quick look at the implementation suggests that truncate() only works for filehandles currently.
But a PerlIO::Scalar "is" a file handle :-(
That said we there isn't a ftruncate() hook in PerlIO virtualization so I don't know what we do...
Adding _only_ ftruncate to PerlIO is not the Right Thing to do\, because the next bug report would be "Why can't you use the -s operator to get the length of the scalar used by a PerlIO::Scalar handle?"
And I would agree with that. But then we have a bunch of other fields in stat that we would have to lie about or fake by tracking last time touched etc.
And once you have both fstat and ftruncate\, you might as well complete the set and add fchown\, fchmod\, and futimes too.
If we fake times in our fake stat then fake futimes makes sense. But chown an chmod make little sense to me - only the current process can access the scalar so current UID is owner (and can't exec it).
We could accept the calls and set errno to nearest code that made sense\, or perhaps just set the mode so that fake stat saw it.
Have we missed any more fd related calls? If there anything else that we can do to filehandles via perl interface that we missed?
In article \20060902095359\.24952\.8@​llama\.ing\-simmons\.net\, nick@ing-simmons.net (Nick Ing-Simmons) wrote:
If we fake times in our fake stat then fake futimes makes sense. But chown an chmod make little sense to me - only the current process can access the scalar so current UID is owner (and can't exec it).
That's true for scalar i/o\, but they would be useful for other kinds of virtual file. An SFTP client comes to mind.
Have we missed any more fd related calls?
ioctl and fcntl. I don't know about the former\, but a virtual O_NONBLOCK flag might be useful.
/Bo Lindbergh
I find this bug still present\, and affecting a unit test of mine (wherein I construct scalar filehandles to pass to the function under test to avoid touching the real FS):
$ perlsh eval: open my $fh\, ">"\, \my $content; '1'
eval: $fh->print( "AAAAAAAAAA" ); '1'
eval: $fh->seek(0\,0); $fh->truncate(0) undef
eval: $fh->print( "BB" ) '1'
eval: $content 'BBAAAAAAAA'
This is on:
$ perl -v
This is perl 5\, version 18\, subversion 1 (v5.18.1) built for x86_64-linux-gnu-thread-multi(with 46 registered patches\, see perl -V for more detail)
While I await a fix - any known workarounds? E.g. a Tie module?
-- Paul "LeoNerd" Evans
leonerd@leonerd.org.uk ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/
Migrated from rt.perl.org#40241 (status was 'open')
Searchable as RT40241$