----- Original Message ----- 
From: "Dan Jablonsky" <[EMAIL PROTECTED]>
To: <perl-win32-users@listserv.ActiveState.com>
Sent: Friday, November 17, 2006 8:55 AM
Subject: problem with tar.gz read


> Hi everybody,
> I guess I still have a problem with my reading of
> tar.gz files. Everything work juuuust great with the
> code below until I happened to hit a corrupted file
> and I can't see a way to jump over it. My point is
> that in a list with hundreds of tar.gz files all of
> them are valid, less one (of small size which also
> happens to be quite at the top of the list) which
> makes the script to go kaboom.
>
> &File::Find::find( sub {
>  #traversing a file structure
>  if($_ =~/\.tar\.gz/)
>   {
>    #if you found a tar.gz file - open and read
>    #build an Archive::Tar object
>    my $tar = Archive::Tar->new($_);

Check that $tar is a true value. (Judging by what you said it *will* be true
even if $_ is corrupt ... so that's not going to help ... but check anyway.)

Otherwise, how about something like:

my $tar = Archive::Tar->new();

eval{ $tar->read($_, 1)};
if($@) {
  warn "$_ is a corrupt file: [EMAIL PROTECTED]";
  # Don't do anything else with this file
}

else {

>    my @files = $tar->list_files() or die "Can't read
> TAR.GZ file!\n";
>    #go thru the array and look for the pattern
>    foreach my $tar_member (@files)
>     {
>      if($tar_member =~/$search_pattern/)
>       {
> print "\nI FOUND 1 file!\n";
> #must extract the found file from the archive
> $tar->extract_file($tar_member, $some_path);
>       }
>     }
>   }

} # close else block

> }, $search_directory);
>

If the read() succeeds on corrupt files (which I think is unlikely) then you
might have to eval{} some of the other method calls that *are* failing.

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to