Changeset 241


Ignore:
Timestamp:
04/24/06 20:10:19 (18 years ago)
Author:
nanardon
Message:
  • end lha support, all test should pass now
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/soft/ObsData/ObsData/Archive/Lha.pm

    r240 r241  
    66use warnings; 
    77use File::Copy; 
    8 use File::Temp qw/ tempfile /; 
     8use File::Temp qw/ tempdir /; 
    99use ObsData::Archive; 
    1010 
     
    4141    my ($self, $file, $dest) = @_; 
    4242 
    43     my ($fh, $fname); 
     43    my $dir = tempdir(); 
     44 
     45    if (system("lha xfw=$dir '$self->{archive}' '$file'")) { 
     46         $self->seterror("Can't uncompress archive: $!"); 
     47         return undef; 
     48    } 
    4449     
    4550    if ($dest) { 
    46         $fname = $dest; 
    47         open($fh, '>', $dest) or do { 
     51        open(my $fh, '>', $dest) or do { 
    4852            $self->seterror("Can't uncompress archive: $!"); 
    4953            return undef; 
    5054        }; 
    51     } else { 
    52         ($fh, $fname) = tempfile( 
    53             DIR => $self->_tempdir, 
    54             UNLINK => 1, 
    55         ) or do { 
    56             $self->seterror("Can't create temp file: $!"); 
     55        open(my $sourcefh, '<', "$dir/$file") or do { 
     56            $self->seterror("Can't open temp file for reading: $!"); 
    5757            return undef; 
    5858        }; 
    59     } 
    6059 
    61     open(my $sourcefh, "unrar p -ierr '$self->{archive}' '$file' 2>/dev/null |") or return undef; 
    62      
    63     if(!copy($sourcefh, $fh)) { 
    64         $self->seterror("Can't copy file to destination: $!"); 
    65         unlink($fname); 
    66         return undef; 
     60        if(!copy($sourcefh, $fh)) { 
     61            $self->seterror("Can't copy file to destination: $!"); 
     62            unlink("$dir/$file"); 
     63            return undef; 
     64        } 
     65        close($fh); 
     66        close($sourcefh); 
    6767    } 
    6868     
    69     close($fh); 
    70     # FIXME unrar sucks, does return a proper exit status on error (allways 0) 
    71     if(!close($sourcefh)) { 
    72         $self->seterror("unrar -p exit with error" . ($! ? (" " . $!) : "")); 
    73         unlink($fname); 
    74         return undef; 
    75     } 
    76     $fname 
     69    return $dest || "$dir/$file"; 
    7770} 
    7871 
Note: See TracChangeset for help on using the changeset viewer.