From: | CARNIL [...] cpan.org |
Subject: | extractMemberWithoutPaths: wrong manpage or wrong behaviour |
Hi
This bug has been forwarded from http://bugs.debian.org/692360
----cut---------cut---------cut---------cut---------cut---------cut-----
Package: libarchive-zip-perl
Version: 1.30-6
Severity: normal
Tags: upstream
The manpage of Archive::Zip states:
extractMemberWithoutPaths( $memberOrName [, $extractedName ] )
Extract the given member, or match its name and extract it. Does not use path information
(extracts into the current directory). Returns undef if member doesn't exist in this Zip. If
optional second arg is given, use it as the name of the extracted member (its paths will be
deleted too). Otherwise, the internal filename of the member (minus paths) is used as the name of
the extracted file or directory. Returns "AZ_OK" on success.
It's not true. If you pass a pathname as the second argument
- the leading directories(!) are created (should be noted in the man page, as
from my POV it's not common in the unix world.)
- the pathname is used as the name for the extracted file
The man page states, that paths will be removed too from the second
argument.
I'm not sure how to solve the problem. It could be fixed easily around
line 202ff in Archive/Zip/Archive.pm, but I'd be afraid that this could
break existing applications (at least mine ☺)
Here is some code to reproduce the behaviour:
#! /usr/bin/perl
use 5.010;
use strict;
use warnings;
use Archive::Zip;
my $DIR = "/tmp/$$.d/Xtract/";
my $zipfile = shift // die "need name of zip file\n";
my $zip = new Archive::Zip $zipfile or die "Archive::Zip $zipfile: $!\n";
foreach my $member ($zip->members) {
say $member->fileName;
$zip->extractMemberWithoutPaths($member, "$DIR/$name");
}
system "find $DIR/ -ls";
----cut---------cut---------cut---------cut---------cut---------cut-----
I'm not sure if the following is correct to solve this, so moving the 'strip
off of directories' outside:
----cut---------cut---------cut---------cut---------cut---------cut-----
From c76a60f6c4d7c99e8796839d37896529360ef9c4 Mon Sep 17 00:00:00 2001
From: Salvatore Bonaccorso <carnil@debian.org>
Date: Sat, 24 Nov 2012 17:09:53 +0100
Subject: [PATCH] Strip paths in extractMemberWithoutPaths from member's names
---
lib/Archive/Zip/Archive.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/Archive/Zip/Archive.pm b/lib/Archive/Zip/Archive.pm
index d9fd02e..358405c 100644
--- a/lib/Archive/Zip/Archive.pm
+++ b/lib/Archive/Zip/Archive.pm
@@ -217,9 +217,9 @@ sub extractMemberWithoutPaths {
return AZ_OK if $member->isDirectory();
unless ($name) {
$name = $member->fileName();
- $name =~ s{.*/}{}; # strip off directories, if any
- $name = Archive::Zip::_asLocalName($name);
}
+ $name =~ s{.*/}{}; # strip off directories, if any
+ $name = Archive::Zip::_asLocalName($name);
my $rc = $member->extractToFileNamed( $name, @_ );
$member->{'compressedSize'} = $originalSize;
return $rc;
--
1.7.10.4
----cut---------cut---------cut---------cut---------cut---------cut-----
Thanks in advance,
Salvatore Bonaccorso, Debian Perl Group