in reply to Re^5: manipulating cpio archive
in thread manipulating cpio archive

OK, you asked for it (no sarcasm intended):
$VAR1 = bless( { 'list' => [ bless( { 'mode' => 16877, 'nlink' => 2, 'ino' => 63796, 'rdev' => 0, 'dev' => 2056, 'uid' => 1000, 'mtime' => 1295288664, 'name' => '.', 'data' => undef, 'gid' => 1000 }, 'Archive::Cpio::File' ), bless( { 'mode' => 33188, 'nlink' => 1, 'ino' => 63800, 'rdev' => 0, 'dev' => 2056, 'uid' => 1000, 'mtime' => 1295288664, 'name' => 't2', 'data' => undef, 'gid' => 1000 }, 'Archive::Cpio::File' ), bless( { 'mode' => 33188, 'nlink' => 1, 'ino' => 63799, 'rdev' => 0, 'dev' => 2056, 'uid' => 1000, 'mtime' => 1295288664, 'name' => 't1', 'data' => undef, 'gid' => 1000 }, 'Archive::Cpio::File' ), bless( { 'mode' => 33188, 'nlink' => 1, 'ino' => 63801, 'rdev' => 0, 'dev' => 2056, 'uid' => 1000, 'mtime' => 1295288664, 'name' => 't3', 'data' => undef, 'gid' => 1000 }, 'Archive::Cpio::File' ) ], 'archive_format' => bless( { 'magic' => 29127 }, 'Archive::Cpio::OldBina +ry' ) }, 'Archive::Cpio' );

Replies are listed 'Best First'.
Re^7: manipulating cpio archive
by Corion (Patriarch) on Jan 17, 2011 at 20:15 UTC

    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.

      Thank you.
      You put it more precise, but I already concluded that the code could not be right. I hope a fix will be made, there is an outstanding bug 2 years old. This code is a bit over my head.
        As I already wrote, this code is over my head. I would like to fix the old code temporarily
        OLD BUGGED CODE: 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}}; }
        with something like this
        WRONG NEW CODE sub remove { my ($cpio, @filenames) = @_; $cpio->{list} or die "can't remove from nothing\n"; foreach $item (@{$cpio->{list}}) { foreach $file (@filesnames) { if ($item->{name} eq $file){ delete @{$cpio2->{list}->{$item}}; } } } return; }
        How should this be done?