Changeset 241
- Timestamp:
- 04/24/06 20:10:19 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/soft/ObsData/ObsData/Archive/Lha.pm
r240 r241 6 6 use warnings; 7 7 use File::Copy; 8 use File::Temp qw/ temp file/;8 use File::Temp qw/ tempdir /; 9 9 use ObsData::Archive; 10 10 … … 41 41 my ($self, $file, $dest) = @_; 42 42 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 } 44 49 45 50 if ($dest) { 46 $fname = $dest; 47 open($fh, '>', $dest) or do { 51 open(my $fh, '>', $dest) or do { 48 52 $self->seterror("Can't uncompress archive: $!"); 49 53 return undef; 50 54 }; 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: $!"); 57 57 return undef; 58 58 }; 59 }60 59 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); 67 67 } 68 68 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"; 77 70 } 78 71
Note: See TracChangeset
for help on using the changeset viewer.