Subject: | 'remove' does not behave as intended |
Date: | Mon, 17 Jan 2011 21:53:40 +0100 |
To: | bug-Archive-Cpio [...] rt.cpan.org |
From: | vwf <vwf [...] vulkor.net> |
Dear Sir,
I would like to report a bug in Archive::Cpio, the remove method.
In short, the method does not remove a file entry from the archive.
As one of the perlmonks wrote:
"I would asume that this is a bug in Archive::Cpio. The ->remove subroutine
treats $archive->{list} as an array of strings (as do the examples), but it
contains Archive::Cpio::File objects that don't seem to have stringification
overload.
You'll likely need to rewrite the ->remove method to actually remove elements
by their ->name (and raise a bug against the module, please).
The test suite only tests that the (main) module can be loaded and tests no
functionality at all, so adding a test for ->remove wouldn't hurt either."
My archive is td.cpio:
$ cpio --list -i <td.cpio
.
t2
t1
t3
1 block
$
My script is
#!/opt/ActivePerl-5.12/bin/perl
use Archive::Cpio;
my $cpio = Archive::Cpio->new;
$cpio->read('td.cpio');
$cpio->remove('t1');
$cpio->write('tdnew.cpio');
The output tdnew.cpio is identical to td.cpio
I think the answer is in the Archive::Cpio code. The entry should be removed in
sub remove {
my ($cpio, @filenames) = @_;
$cpio->{list} or die "can't remove from nothing\n";
my %filenames = map { $_ => 1 } @filenames;
@{$cpio->{list}} = grep { !$filenames{$_} } @{$cpio->{list}};
}
Unfortunately, it does not.
All with Activestate Perl 5.12.2 and Archive::Cpio 0.07
on Debian Linux Stable (Lenny)
Thank you,
Frits