Skip Menu |

This queue is for tickets about the Archive-Cpio CPAN distribution.

Report information
The Basics
Id: 64852
Status: resolved
Priority: 0/
Queue: Archive-Cpio

People
Owner: Nobody in particular
Requestors: vwf [...] vulkor.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Subject: [rt.cpan.org #64852] easy fix
Date: Wed, 26 Jan 2011 18:34:20 +0100
To: bug-Archive-Cpio [...] rt.cpan.org
From: vwf <vwf [...] vulkor.net>
This works: (all credit to Corion @PerlMonks) sub remove { my ($cpio, @filenames) = @_; $cpio->{list} or die "can't remove from nothing\n"; # Create a lookup table of names to be removed my %filenames = map { $_ => 1 } @filenames; # This was the old, buggy code # @{$cpio->{list}} = grep { !$filenames{$_} } @{$cpio->{list}}; # Remove the elements according to their name: @{$cpio->{list}} = grep { !$filenames{$_->name} } @{$cpio->{list}}; }
thanks a lot for the fix, i did not have the time to look at it yet /o\ fix applied and released in version 0.08