Changeset 443
- Timestamp:
- 06/12/09 15:51:44 (15 months ago)
- File:
-
- 1 edited
-
branches/2.4/classes/phing/tasks/ext/UnzipTask.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4/classes/phing/tasks/ext/UnzipTask.php
r144 r443 21 21 require_once 'phing/tasks/ext/ExtractBaseTask.php'; 22 22 require_once 'phing/system/io/FileSystem.php'; 23 require_once 'phing/lib/Zip.php';24 23 25 24 /** 26 * Extracts one or several zip archive using PEAR Archive_Zip (which is presently unreleased 27 * and included with Phing). 25 * Extracts one or several zip archives using ZipArchive class. 28 26 * 29 * @author Joakim Bodin <joakim.bodin+phing@gmail.com>30 * @ version $Revision: 1.0 $31 * @ package phing.tasks.ext32 * @ since 2.2.027 * @author Joakim Bodin <joakim.bodin+phing@gmail.com> 28 * @author George Miroshnikov <laggy.luke@gmail.com> 29 * @version $Revision$ 30 * @package phing.tasks.ext 33 31 */ 34 class UnzipTask extends ExtractBaseTask { 35 32 class UnzipTask extends ExtractBaseTask 33 { 34 /** 35 * Extract archive content into $this->todir directory 36 * @param PhingFile Zip file to extract 37 * @return boolean 38 */ 36 39 protected function extractArchive(PhingFile $zipfile) 37 40 { 38 $extractParams = array('add_path' => $this->todir->getAbsolutePath()); 39 if(!empty($this->removepath)) 40 { 41 $extractParams['remove_path'] = $this->removepath; 41 $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO); 42 43 $zip = new ZipArchive(); 44 45 $result = $zip->open($zipfile->getAbsolutePath()); 46 if (!$result) { 47 $this->log("Unable to open zipfile " . $zipfile->__toString(), Project::MSG_ERR); 48 return false; 42 49 } 43 50 44 $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO); 51 $result = $zip->extractTo($this->todir->getAbsolutePath()); 52 if (!$result) { 53 $this->log("Unable to extract zipfile " . $zipfile->__toString(), Project::MSG_ERR); 54 return false; 55 } 45 56 46 try { 47 $zip = new Archive_Zip($zipfile->getAbsolutePath()); 48 49 $extractResponse = $zip->extract($extractParams); 50 if(is_array($extractResponse)) { 51 foreach ($extractResponse as $extractedPath) { 52 $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), Project::MSG_VERBOSE); 53 } 54 } else if ($extractResponse === 0) { 55 throw new BuildException('Failed to extract zipfile: ' . $zip->errorInfo(true)); 56 } 57 } catch (IOException $ioe) { 58 $msg = "Could not extract ZIP: " . $ioe->getMessage(); 59 throw new BuildException($msg, $ioe, $this->getLocation()); 60 } 57 return true; 61 58 } 62 59 60 /** 61 * List archive content 62 * @param PhingFile Zip file to list content 63 * @return array List of files inside $zipfile 64 */ 63 65 protected function listArchiveContent(PhingFile $zipfile) 64 66 { 65 $zip = new Archive_Zip($zipfile->getAbsolutePath()); 66 return $zip->listContent(); 67 $zip = new ZipArchive(); 68 $zip->open($zipfile->getAbsolutePath()); 69 70 $content = array(); 71 for ($i = 0; $i < $zip->numFiles; $i++) { 72 $content[] = $zip->getNameIndex($i); 73 } 74 return $content; 67 75 } 68 76 } 77
Note: See TracChangeset
for help on using the changeset viewer.
