Beispiel #1
0
 public function getKey()
 {
     if (null !== $this->_targetPackage) {
         return $this->_targetPackage->getKey();
     } else {
         return $this->_currentPackage->getKey();
     }
 }
 public static function deflate(Engine_Package_Manifest $package, $outputPath)
 {
     // Sanity
     if (!file_exists($outputPath) || !is_dir($outputPath) || !is_writeable($outputPath)) {
         throw new Engine_Package_Exception('Output path does not exist, is not a directory, or is not writeable');
     }
     if (!is_dir($package->getBasePath())) {
         throw new Engine_Package_Exception('Missing package base path');
     }
     self::_loadArchiveClass();
     // Make filenames and paths
     $basePath = $package->getBasePath();
     $archiveFile = $package->getKey() . '.tar';
     $archiveFullPath = $outputPath . DIRECTORY_SEPARATOR . $archiveFile;
     if (file_exists($archiveFullPath) && !unlink($archiveFullPath)) {
         throw new Engine_Package_Exception('Target archive already exists and unable to remove');
     }
     // Start packing
     $archive = new Archive_Tar($archiveFullPath);
     $archive->setIgnoreList(array('CVS', '.svn'));
     // Add all directories, files, and subpackages
     $package->addToArchive($archive);
     return $archiveFullPath;
 }
 public function extractAction()
 {
     $this->_helper->contextSwitch->initContext();
     $package = $this->_getParam('package');
     // Setup
     try {
         $archiveDir = $this->_packageManager->getTemporaryPath(Engine_Package_Manager::PATH_ARCHIVES);
         $extractDir = $this->_packageManager->getTemporaryPath(Engine_Package_Manager::PATH_PACKAGES);
     } catch (Exception $e) {
         $this->view->error = $e->getMessage();
         return;
     }
     // Check if archive is a tar file
     $targetFile = $archiveDir . DIRECTORY_SEPARATOR . $package;
     if (strtolower(substr($targetFile, -4, 4)) != '.tar') {
         $this->view->error = 'Package is not a TAR archive.';
         return;
     }
     // Check if archive exists
     if (!file_exists($targetFile)) {
         $this->view->error = 'Package does not exist.';
         return;
     }
     // Try to deflate archive?
     $extractFiles = array($targetFile);
     $packagesInfo = array();
     @set_time_limit(300);
     $toRemove = array();
     try {
         while (count($extractFiles) > 0) {
             $current = array_shift($extractFiles);
             $hadPackage = false;
             $hadArchive = false;
             // Try to extract
             $outputPath = Engine_Package_Archive::inflate($current, $extractDir);
             // Check for tar files or package files
             foreach (scandir($outputPath) as $child) {
                 // Package file
                 if (strtolower($child) == 'package.json') {
                     $packageFile = new Engine_Package_Manifest($outputPath . DIRECTORY_SEPARATOR . $child);
                     $packagesInfo[] = array('key' => $packageFile->getKey(), 'data' => $packageFile->toArray(), 'html' => $this->view->packageSelect($packageFile));
                     $hadPackage = true;
                 } else {
                     if (strtolower(substr($child, -4)) === '.tar') {
                         $extractFiles[] = $outputPath . DIRECTORY_SEPARATOR . $child;
                         $hadArchive = true;
                     }
                 }
             }
             // Add to remove after extraction
             $toRemove[] = $current;
             if (!$hadPackage) {
                 $toRemove[] = $outputPath;
             }
         }
     } catch (Exception $e) {
         $this->view->error = $e->getMessage();
         return;
     }
     if (empty($packagesInfo)) {
         $this->view->error = 'No packages found in archive';
         return;
     }
     // Remove to remove
     foreach ($toRemove as $removeFile) {
         if (is_dir($removeFile)) {
             try {
                 Engine_Package_Utilities::fsRmdirRecursive($removeFile, true);
             } catch (Exception $e) {
             }
         } else {
             if (is_file($removeFile)) {
                 @unlink($removeFile);
             }
         }
     }
     $this->view->status = 1;
     $this->view->packagesInfo = $packagesInfo;
 }