problem with tar.gz read

2006-11-16 Thread Dan Jablonsky
Hi everybody,
I guess I still have a problem with my reading of
tar.gz files. Everything work jst 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($_);
   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);
  }
} 
  }
}, $search_directory);

So, the problem is that my script gets to the line
with my $tar = Archive::Tar-new($_); but starts to
print error messages like:
Couldn't read chunk at offset unknown at C:\path\to
my\script.pl
...
Illegal octal digit '9' ignored at
C:/Perl/site/lib/Archive/Tar/File.pm line 206 and so
on ...

Is there a way to verify the validity of the Tar (or
the file) BEFORE I call the new for the Archive::Tar
object and in case the file is not valid allow to skip
it? By the way, when I try to open the said tar.gz,
WinZip reports :Invalid Archive Directory!

Thanks a bunch,
Dan



 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: problem with tar.gz read

2006-11-16 Thread Sisyphus

- 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 jst 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