Subject: | patch for tar and zip handlers |
I've created a patch for JSAN::Index::Release. zip handler was absent
and tar handler was not working properly.
Subject: | tar_and_zip.txt |
sub _extract_resource_from_tar {
my ($self, $resource, %params) = @_;
my $tar = $self->archive;
my @files = $tar->get_files;
# Determine which files to extract, and to where
my $extracted_files = 0;
foreach my $item ( @files ) {
next if !$item->is_file;
# Split into parts and remove the top level dir
my ($vol, $dir, $file)
= File::Spec->splitpath( $item->full_path );
my @dirs = File::Spec->splitdir( $dir );
shift @dirs;
# Is this file in the resource directory
my $res = shift( @dirs ) or next;
next if $res ne $resource;
# These are STILL relative, but we'll deal with that later.
my $write_dir = File::Spec->catfile( $params{to}, @dirs );
# Write the file
$self->_write( $write_dir, $file, $item->get_content );
$extracted_files++;
}
# Return the number of files, or error if none
return $extracted_files if $extracted_files;
my $path = $self->source;
Carp::croak("Tarball '$path' does not contain resource '$resource'");
}
sub _extract_resource_from_zip {
my ($self, $resource, %params) = @_;
my $zip = $self->archive;
my @files = $zip->members;
# Determine which files to extract, and to where
my $extracted_files = 0;
my $is_file = sub { $_[0]->isTextFile || $_[0]->isBinaryFile };
foreach my $item ( @files ) {
next if ! $is_file->($item);
# Split into parts and remove the top level dir
my ($vol, $dir, $file)
= File::Spec::Unix->splitpath( $item->fileName );
my @dirs = File::Spec::Unix->splitdir( $dir );
shift @dirs;
# Is this file in the resource directory
my $res = shift( @dirs ) or next;
next if $res ne $resource;
# These are STILL relative, but we'll deal with that later.
my $write_dir = File::Spec->catfile( $params{to}, @dirs );
# Write the file
$self->_write( $write_dir, $file, $item->contents );
$extracted_files++;
}
# Return the number of files, or error if none
return $extracted_files if $extracted_files;
my $path = $self->source;
Carp::croak("Zip '$path' does not contain resource '$resource'");
}