Ticket #259: UntarTask.php.patch
| File UntarTask.php.patch, 2.7 kB (added by mazzarelli@gmail.com, 6 months ago) |
|---|
-
UntarTask.php
old new 29 29 * @since 2.2.0 30 30 */ 31 31 class UntarTask extends ExtractBaseTask { 32 32 33 33 /** 34 34 * Ensures that PEAR lib exists. 35 35 */ … … 39 39 throw new BuildException("You must have installed the PEAR Archive_Tar class in order to use UntarTask."); 40 40 } 41 41 } 42 42 43 43 protected function extractArchive(PhingFile $tarfile) 44 44 { 45 45 $this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO); 46 47 try {48 $tar = $this->initTar($tarfile);49 if(!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) {50 throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath());51 }46 47 try { 48 $tar = $this->initTar($tarfile); 49 if(!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) { 50 throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath()); 51 } 52 52 } catch (IOException $ioe) { 53 53 $msg = "Could not extract tar file: " . $ioe->getMessage(); 54 54 throw new BuildException($msg, $ioe, $this->getLocation()); 55 55 } 56 56 } 57 57 58 58 protected function listArchiveContent(PhingFile $tarfile) 59 59 { 60 60 $tar = $this->initTar($tarfile); 61 61 return $tar->listContent(); 62 62 } 63 63 64 64 /** 65 65 * Init a Archive_Tar class with correct compression for the given file. 66 66 * … … 71 71 { 72 72 $compression = null; 73 73 $tarfileName = $tarfile->getName(); 74 $mode = substr($tarfileName, strrpos($tarfileName, '.')); 75 switch($mode) { 76 case '.gz': 77 $compression = 'gz'; 74 $mode = strtolower(substr($tarfileName, strrpos($tarfileName, '.'))); 75 76 $compressions = array( 77 'gz' => array('.gz', '.tgz',), 78 'bz2' => array('.bz2',), 79 ); 80 foreach ($compressions as $algo => $ext) { 81 if (array_search($mode, $ext) !== false) { 82 $compression = $algo; 78 83 break; 79 case '.bz2': 80 $compression = 'bz2'; 81 break; 82 case '.tar': 83 break; 84 default: 85 $this->log('Ignoring unknown compression mode: ' . $mode, Project::MSG_WARN); 84 } 86 85 } 87 88 return new Archive_Tar($tarfile->getAbsolutePath(), $compression);86 87 return new Archive_Tar($tarfile->getAbsolutePath(), $compression); 89 88 } 90 89 }
