public function addToArchive(Archive_Tar $archive) { $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath()); if ($archive->isError($rval)) { throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage()); } }
public static function archive($name = false, $listFilesAndFolders, $export_files_dir, $export_files_dir_name, $backupName, $move = false, $identifier, $type) { if (empty($export_files_dir)) { return; } $dir_separator = DIRECTORY_SEPARATOR; $backupName = 'backup' . $dir_separator . $backupName; $installFilePath = 'system' . $dir_separator . 'admin-scripts' . $dir_separator . 'miscellaneous' . $dir_separator; $dbSQLFilePath = 'backup' . $dir_separator; $old_path = getcwd(); chdir($export_files_dir); $tar = new Archive_Tar($backupName, 'gz'); if (SJB_System::getIfTrialModeIsOn()) { $tar->setIgnoreList(array('system/plugins/mobile', 'system/plugins/facebook_app', 'templates/mobile', 'templates/Facebook')); } SessionStorage::write('backup_' . $identifier, serialize(array('last_time' => time()))); switch ($type) { case 'full': $tar->addModify("{$installFilePath}install.php", '', $installFilePath); $tar->addModify($dbSQLFilePath . $name, '', $dbSQLFilePath); $tar->addModify($listFilesAndFolders, ''); SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $name); break; case 'files': $tar->addModify("{$installFilePath}install.php", '', $installFilePath); $tar->addModify($listFilesAndFolders, ''); break; case 'database': $tar->addModify($dbSQLFilePath . $listFilesAndFolders, '', $dbSQLFilePath); SJB_Filesystem::delete($export_files_dir . $dbSQLFilePath . $listFilesAndFolders); break; } chdir($old_path); return true; }
/** * @param string The name of the archive * @param mixed The name of a single file or an array of files * @param string The compression for the archive * @param string Path to add within the archive * @param string Path to remove within the archive * @param boolean Automatically append the extension for the archive * @param boolean Remove for source files */ function create($archive, $files, $compress = 'tar', $addPath = '', $removePath, $autoExt = true) { $compress = strtolower($compress); if ($compress == 'tgz' || $compress == 'tbz' || $compress == 'tar') { require_once _EXT_PATH . '/libraries/Tar.php'; if (is_string($files)) { $files = array($files); } if ($autoExt) { $archive .= '.' . $compress; } if ($compress == 'tgz') { $compress = 'gz'; } if ($compress == 'tbz') { $compress = 'bz2'; } $tar = new Archive_Tar($archive, $compress); $tar->setErrorHandling(PEAR_ERROR_PRINT); $result = $tar->addModify($files, $addPath, $removePath); return $result; } elseif ($compress == 'zip') { $adapter =& xFileArchive::getAdapter('zip'); if ($adapter) { $result = $adapter->create($archive, $files, $removePath); } if ($result == false) { return PEAR::raiseError('Unrecoverable ZIP Error'); } } }
public function addToArchive(Archive_Tar $archive) { // Add top level package manifest $archive->addString('package.json', $this->toString('json')); // Normal stuff parent::addToArchive($archive); }
function testBz2() { $oTar = new Archive_Tar($this->sFileBz2, 'bz2'); $sExpected = $oTar->extractInString('Beautifier.php'); unset($oTar); $sActual = file_get_contents('tarz://' . $this->sFileBz2 . "#Beautifier.php"); $this->assertTrue($sExpected == $sActual, 'file_get_contents'); }
function install($file) { G::LoadThirdParty("pear/Archive", "Tar"); $result = array(); $status = 1; try { //Extract $tar = new Archive_Tar($file); $swTar = $tar->extract(PATH_OUTTRUNK); //true on success, false on error. //directory for extract //$swTar = $tar->extract(PATH_PLUGINS); if (!$swTar) { throw new Exception("Could not extract file."); } //Upgrade $option = array("http" => array("method" => "POST")); // Proxy settings $sysConf = System::getSystemConfiguration(); if (isset($sysConf['proxy_host'])) { if ($sysConf['proxy_host'] != '') { if (!is_array($option['http'])) { $option['http'] = array(); } $option['http']['request_fulluri'] = true; $option['http']['proxy'] = 'tcp://' . $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : ''); if ($sysConf['proxy_user'] != '') { if (!isset($option['http']['header'])) { $option['http']['header'] = ''; } $option['http']['header'] .= 'Proxy-Authorization: Basic ' . base64_encode($sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '')); } } } $context = stream_context_create($option); /////// $fileData = @fopen(EnterpriseUtils::getUrlServerName() . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/enterprise/services/processMakerUpgrade", "rb", false, $context); if ($fileData === false) { throw new Exception("Could not open services url."); } $resultAux = G::json_decode(stream_get_contents($fileData)); if ($resultAux->status == "OK") { $result["status"] = $resultAux->status; //OK $result["message"] = $resultAux->message; } else { throw new Exception($resultAux->message); } } catch (Exception $e) { $result["message"] = $e->getMessage(); $status = 0; } if ($status == 0) { $result["status"] = "ERROR"; } return $result; }
public static function expand($path) { $path = realpath($path); $dir = dirname($path); #print ">> $path\n"; $arch = new Archive_Tar($path, true); $arch->setErrorHandling(PEAR_ERROR_PRINT); if (false === $arch->extract($dir)) { throw new Pfw_Exception_Script(Pfw_Exception_Script::E_ARCHIVE_UNKNOWN); } }
/** * @param string $tar - path to tar file */ public function __construct($_tar) { $tar = new Archive_Tar($_tar); $this->package_xml = $tar->extractInString('package.xml'); unset($tar); $this->parse_package(); $files = $this->files(); // $xml = simplexml_load_string(str_replace('xmlns=', 'xmlns:default=', $this->package_xml)); // $namespaces = $xml->getNamespaces(true); // $xml->registerXPathNamespace('default', 'default'); }
protected function getArchive() { $obj = new Archive_Tar($this->getBackupFile()); if (!is_file($this->getBackupFile())) { $files = array(); if (!$obj->create($files)) { echo "can't create archive"; } } return $obj; }
public static function generateTarByPluginDir(array $info, $filename, $input, $output) { $timeLimit = ini_get('max_execution_time'); set_time_limit(0); require_once 'Archive/Tar.php'; $tar = new Archive_Tar($output . '/' . $filename, true); foreach ($info['filelist'] as $file => $data) { $tar->addString($info['name'] . '-' . $info['version'] . '/' . $file, file_get_contents($input . '/' . $file)); } $tar->addString('package.xml', file_get_contents($input . '/package.xml')); set_time_limit($timeLimit); }
function archive_extract($path, $archive_dir, $config = array()) { $result = FALSE; if (class_exists('Archive_Tar')) { if (file_safe(path_concat($archive_dir, 'file.txt'), $config)) { $tar = new Archive_Tar($path); $tar->extract($archive_dir); $result = file_exists($archive_dir); } } return $result; }
function extract_archive($path, $archive_dir) { $result = FALSE; if (class_exists('Archive_Tar')) { if (safe_path($archive_dir)) { $tar = new Archive_Tar($path); $tar->extract(dirname($archive_dir)); $result = file_exists($archive_dir); } } return $result; }
public function installFromFile($file) { require_once "/var/www/localhost/htdocs/papyrine/libraries/PEAR.php"; require_once "/var/www/localhost/htdocs/papyrine/libraries/Archive_Tar.php"; $tar = new Archive_Tar($file, 'bz2'); $about = $tar->extractInString("about.xml"); $xml = simplexml_load_string($about); $dir = "/var/www/localhost/htdocs/papyrine/data/plugins/tmp/" . $xml->id . "/"; if (!is_dir($dir)) { $tar->extract($dir); } $this->installFromDirectory($dir); }
protected function _untarIntoTemp($path) { $original_dir = getcwd(); //create a temp file, turn it into a directory $dir = tempnam('/tmp', 'mt2c'); unlink($dir); mkdir($dir); chdir($dir); $tar = new Archive_Tar($path); $tar->extract('.'); chdir($original_dir); return $dir; }
static function install($source, $filename) { $target = SIMPLE_EXT . substr($filename, 0, -3); setup::out("{t}Download{/t}: " . $source . " ..."); if ($fz = gzopen($source, "r") and $fp = fopen($target, "w")) { $i = 0; while (!gzeof($fz)) { $i++; setup::out(".", false); if ($i % 160 == 0) { setup::out(); } fwrite($fp, gzread($fz, 16384)); } gzclose($fz); fclose($fp); } else { sys_die("{t}Error{/t}: gzopen [2] " . $source); } setup::out(); if (!file_exists($target) or filesize($target) == 0 or filesize($target) % 10240 != 0) { sys_die("{t}Error{/t}: file-check [3] Filesize: " . filesize($target) . " " . $target); } setup::out(sprintf("{t}Processing %s ...{/t}", basename($target))); $tar_object = new Archive_Tar($target); $tar_object->setErrorHandling(PEAR_ERROR_PRINT); $tar_object->extract(SIMPLE_EXT); $file_list = $tar_object->ListContent(); if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir(SIMPLE_EXT . $file_list[0]["filename"])) { sys_die("{t}Error{/t}: tar [4] " . $target); } self::update_modules_list(); $ext_folder = db_select_value("simple_sys_tree", "id", "anchor=@anchor@", array("anchor" => "extensions")); foreach ($file_list as $file) { sys_chmod(SIMPLE_EXT . $file["filename"]); setup::out(sprintf("{t}Processing %s ...{/t}", SIMPLE_EXT . $file["filename"])); if (basename($file["filename"]) == "install.php") { setup::out(""); require SIMPLE_EXT . $file["filename"]; setup::out(""); } if (basename($file["filename"]) == "readme.txt") { $data = file_get_contents(SIMPLE_EXT . $file["filename"]); setup::out(nl2br("\n" . q($data) . "\n")); } if (!empty($ext_folder) and basename($file["filename"]) == "folders.xml") { setup::out(sprintf("{t}Processing %s ...{/t}", "folder structure")); folders::create_default_folders(SIMPLE_EXT . $file["filename"], $ext_folder, false); } } }
static function extract($target, $folder) { setup::out(sprintf("{t}Processing %s ...{/t}", basename($target))); $tar_object = new Archive_Tar($target); $tar_object->setErrorHandling(PEAR_ERROR_PRINT); $tar_object->extract($folder); $file_list = $tar_object->ListContent(); if (!is_array($file_list) or !isset($file_list[0]["filename"]) or !is_dir($folder . $file_list[0]["filename"])) { sys_die("{t}Error{/t}: tar [3] " . $target); } foreach ($file_list as $file) { sys_chmod($folder . $file["filename"]); } @unlink($target); return $folder . $file_list[0]["filename"]; }
public static function readPackageFile($file) { // Sanity if (!file_exists($file) || !is_file($file) || strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'tar') { throw new Engine_Package_Exception('File does not exist or is not a tar file'); } self::_loadArchiveClass(); // Create archive object $archive = new Archive_Tar($file); // List files $fileList = $archive->listContent(); if (empty($fileList)) { throw new Engine_Package_Exception('Unable to open archive'); } // Check for root package file $rootPackageFile = null; foreach ($fileList as $arFile) { if ($arFile['filename'] == 'package.json') { $rootPackageFile = $arFile['filename']; break; } } if (null === $rootPackageFile) { throw new Engine_Package_Exception('Root package file not found.'); } // Start building package stuff $packageFileObject = new Engine_Package_Manifest(); $packageFileObject->fromString($archive->extractInString($rootPackageFile), 'json'); return $packageFileObject; }
/** * The most basic file transaction: add a single entry (file or directory) to * the archive. * * @param bool $isVirtual If true, the next parameter contains file data instead of a file name * @param string $sourceNameOrData Absolute file name to read data from or the file data itself is $isVirtual is true * @param string $targetName The (relative) file name under which to store the file in the archive * @return True on success, false otherwise * @since 2.1 * @access protected * @abstract */ function _addFile($isVirtual, &$sourceNameOrData, $targetName) { if ($isVirtual) { // VIRTUAL FILES // Create and register temp file with the virtual contents $tempFileName = JoomlapackCUBETempfiles::registerTempFile(basename($targetName)); if (function_exists('file_put_contents')) { file_put_contents($tempFileName, $sourceNameOrData); } else { $tempHandler = fopen($tempFileName, 'wb'); $this->_fwrite($tempHandler, $sourceNameOrData); fclose($tempHandler); } // Calculate add / remove paths $removePath = dirname($tempFileName); $addPath = dirname($targetName); // Add the file $this->_tarObject->addModify($tempFileName, $addPath, $removePath, $tempFileName); // Remove the temporary file JoomlapackCUBETempfiles::unregisterAndDeleteTempFile(basename($targetName)); } else { // REGULAR FILES if ($targetName == '') { $targetName = $sourceNameOrData; } $this->_tarObject->addModify($sourceNameOrData, '', JPATH_SITE, $targetName); } }
/** * Execute the action * * @return mixed * @access public * @since 1/17/08 */ public function execute() { $harmoni = Harmoni::instance(); $component = SiteDispatcher::getCurrentNode(); $site = SiteDispatcher::getCurrentRootNode(); $slotMgr = SlotManager::instance(); $slot = $slotMgr->getSlotBySiteId($site->getId()); $exportDir = DATAPORT_TMP_DIR . "/" . $slot->getShortname() . "-" . str_replace(':', '_', DateAndTime::now()->asString()); mkdir($exportDir); try { // Do the export $visitor = new DomExportSiteVisitor($exportDir); $component->acceptVisitor($visitor); // Validate the result // printpre(htmlentities($visitor->doc->saveXMLWithWhitespace())); // $tmp = new Harmoni_DomDocument; // $tmp->loadXML($visitor->doc->saveXMLWithWhitespace()); // $tmp->schemaValidateWithException(MYDIR."/doc/raw/dtds/segue2-site.xsd"); $visitor->doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); // Write out the XML $visitor->doc->saveWithWhitespace($exportDir . "/site.xml"); $archive = new Archive_Tar($exportDir . ".tar.gz"); $archive->createModify($exportDir, '', DATAPORT_TMP_DIR); // Remove the directory $this->deleteRecursive($exportDir); header("Content-Type: application/x-gzip;"); header('Content-Disposition: attachment; filename="' . basename($exportDir . ".tar.gz") . '"'); print file_get_contents($exportDir . ".tar.gz"); // Clean up the archive unlink($exportDir . ".tar.gz"); } catch (PermissionDeniedException $e) { $this->deleteRecursive($exportDir); if (file_exists($exportDir . ".tar.gz")) { unlink($exportDir . ".tar.gz"); } return new Block(_("You are not authorized to export this component."), ALERT_BLOCK); } catch (Exception $e) { $this->deleteRecursive($exportDir); if (file_exists($exportDir . ".tar.gz")) { unlink($exportDir . ".tar.gz"); } throw $e; } error_reporting(0); exit; }
protected function execute($arguments = array(), $options = array()) { $pluginName = $arguments['name']; $packagePath = sfConfig::get('sf_plugins_dir') . '/' . $pluginName; if (!is_readable($packagePath . '/package.xml')) { throw new sfException(sprintf('Plugin "%s" dosen\'t have a definition file.', $pluginName)); } $infoXml = simplexml_load_file($packagePath . '/package.xml'); $filename = sprintf('%s-%s.tgz', (string) $infoXml->name, (string) $infoXml->version->release); $dirPath = sfConfig::get('sf_plugins_dir') . '/' . $pluginName; $tar = new Archive_Tar($arguments['dir'] . '/' . $filename, true); foreach ($infoXml->contents->dir->file as $file) { $attributes = $file->attributes(); $name = (string) $attributes['name']; $tar->addString($pluginName . '-' . (string) $infoXml->version->release . '/' . $name, file_get_contents($dirPath . '/' . $name)); } $tar->addString('package.xml', file_get_contents($dirPath . '/package.xml')); }
function nc_tgz_create($archive_name, $file_name, $additional_path = '', $exclude_tag = NULL) { global $DOCUMENT_ROOT, $SUB_FOLDER; @set_time_limit(0); $path = $DOCUMENT_ROOT . $SUB_FOLDER . $additional_path; if (SYSTEM_TAR) { $exclude_tag_cmd = ''; if ($exclude_tag) { $exclude_array_tmp = nc_exclude_tag_to_array($path, $exclude_tag); $exclude_array = array(); foreach ($exclude_array_tmp as $item) { $exclude_array[] = '--exclude=' . preg_quote(ltrim(substr($item, strlen($path)), '/')); } $exclude_tag_cmd = implode(' ', $exclude_array); } exec("cd {$path}; tar -zcf '{$archive_name}' {$exclude_tag_cmd} {$file_name} 2>&1", $output, $err_code); if ($err_code) { trigger_error("{$output['0']}", E_USER_WARNING); return false; } return true; } else { $tar_object = new Archive_Tar($archive_name, "gz"); $tar_object->setErrorHandling(PEAR_ERROR_PRINT); if ($exclude_tag) { $exclude_array_tmp = nc_exclude_tag_to_array($path, $exclude_tag); $exclude_array = array(); foreach ($exclude_array_tmp as $item) { $exclude_array[] = ltrim(substr($item, strlen($path)), '/'); } $tar_object->setIgnoreList($exclude_array); } chdir($path); ob_start(); $file_name_array = explode(' ', $file_name); $res = $tar_object->create($file_name_array); if (!$res) { ob_end_flush(); } else { ob_end_clean(); } return $res; } }
/** * preprocess Index action. * * @access public * @return string Forward name (null if no errors.) */ function prepare() { if ($this->af->validate() == 0) { list($package, $version) = explode('@', $this->af->get('target_package')); $data_file = $this->backend->ctl->package2dataFile($package, $version); require_once 'Archive/Tar.php'; $tar = new Archive_Tar($data_file, 'gz'); $status = $tar->extract(dirname($data_file)); /* chdir(BASE.'/tmp'); exec('which tar', $which, $status); $command = sprintf('%s xzf %s', $which[0], $data_file); exec($command, $result, $status); */ if ($status == 1) { return null; } $this->ae->add('extract_error', _('file extract error') . sprintf('[STATUS: %s]', $status)); } return 'json_error_reload'; }
function _generateTarFile($compress = true) { $pkgver = (string) $this->xml->name . '-' . (string) $this->xml->version->release; $targetdir = !empty($this->options['targetdir']) ? $this->options['targetdir'] . DIRECTORY_SEPARATOR : ''; $tarname = $targetdir . $pkgver . ($compress ? '.tgz' : '.tar'); $tar = new Archive_Tar($tarname, $compress); $tar->setErrorHandling(PEAR_ERROR_RETURN); $result = $tar->create(array($this->pkginfofile)); if (PEAR::isError($result)) { return $this->raiseError($result); } foreach ($this->files as $roleDir => $files) { $result = $tar->addModify($files, $pkgver, $roleDir); } if (PEAR::isError($result)) { return $this->raiseError($result); } $this->output .= 'Successfully created ' . $tarname . "\n"; return true; }
/** * Validate the preconditions required for this release task. * * @param array $options Additional options. * * @return array An empty array if all preconditions are met and a list of * error messages otherwise. */ public function validate($options) { $errors = array(); $testpkg = Horde_Util::getTempFile(); $archive = new Archive_Tar($testpkg, 'gz'); $archive->addString('a', 'a'); $archive->addString('b', 'b'); $results = exec('tar tzvf ' . $testpkg . ' 2>&1'); // MacOS tar doesn't error out, but only returns the first string (ending in 'a'); if (strpos($results, 'lone zero block') !== false || substr($results, -1, 1) == 'a') { $errors[] = 'Broken Archive_Tar, upgrade first.'; } $remote = new Horde_Pear_Remote(); try { $exists = $remote->releaseExists($this->getComponent()->getName(), $this->getComponent()->getVersion()); if ($exists) { $errors[] = sprintf('The remote server already has version "%s" for component "%s".', $this->getComponent()->getVersion(), $this->getComponent()->getName()); } } catch (Horde_Http_Exception $e) { $errors[] = 'Failed accessing the remote PEAR server.'; } try { Components_Helper_Version::validateReleaseStability($this->getComponent()->getVersion(), $this->getComponent()->getState('release')); } catch (Components_Exception $e) { $errors[] = $e->getMessage(); } try { Components_Helper_Version::validateApiStability($this->getComponent()->getVersion(), $this->getComponent()->getState('api')); } catch (Components_Exception $e) { $errors[] = $e->getMessage(); } if (empty($options['releaseserver'])) { $errors[] = 'The "releaseserver" option has no value. Where should the release be uploaded?'; } if (empty($options['releasedir'])) { $errors[] = 'The "releasedir" option has no value. Where is the remote pirum install located?'; } return $errors; }
protected function execute($arguments = array(), $options = array()) { // Remove E_STRICT and E_DEPRECATED from error_reporting error_reporting(error_reporting() & ~(E_STRICT | E_DEPRECATED)); require_once 'Archive/Tar.php'; $pluginName = $arguments['name']; $packagePath = sfConfig::get('sf_plugins_dir') . '/' . $pluginName; if (!is_readable($packagePath . '/package.xml')) { throw new sfException(sprintf('Plugin "%s" dosen\'t have a definition file.', $pluginName)); } $content = file_get_contents($packagePath . '/package.xml'); $infoXml = opToolkit::loadXmlString($content, array('return' => 'SimpleXMLElement')); $filename = sprintf('%s-%s.tgz', (string) $infoXml->name, (string) $infoXml->version->release); $dirPath = sfConfig::get('sf_plugins_dir') . '/' . $pluginName; $tar = new Archive_Tar($arguments['dir'] . '/' . $filename, true); foreach ($infoXml->contents->dir->file as $file) { $attributes = $file->attributes(); $name = (string) $attributes['name']; $tar->addString($pluginName . '-' . (string) $infoXml->version->release . '/' . $name, file_get_contents($dirPath . '/' . $name)); } $tar->addString('package.xml', file_get_contents($dirPath . '/package.xml')); }
/** * Method to return a listing of the contents of an archived file * * @param boolean $full * @return array */ public function listFiles($full = false) { $files = array(); $list = $this->archive->listContent(); if (!$full) { foreach ($list as $file) { $files[] = $file['filename']; } } else { $files = $list; } return $files; }
public function uploadPackage() { $tgz = $this->getValue('tgz_file'); $svn = $this->getValue('svn_url'); $gitUrl = $this->getValue('git_url'); $gitCommit = $this->getValue('git_commit'); $memberId = sfContext::getInstance()->getUser()->getMemberId(); $pear = opPluginChannelServerToolkit::registerPearChannel($this->getChannel()); if ($tgz) { require_once 'Archive/Tar.php'; $info = $pear->infoFromTgzFile($tgz->getTempName()); if ($info instanceof PEAR_Error) { throw new RuntimeException($info->getMessage()); } $tar = new Archive_Tar($tgz->getTempName()); $xml = ''; foreach ($tar->listContent() as $file) { if ('package.xml' === $file['filename']) { $xml = $tar->extractInString($file['filename']); } } $file = new File(); $file->setFromValidatedFile($tgz); $file->save(); $this->uploadToS3($file); $release = Doctrine::getTable('PluginRelease')->createByPackageInfo($info, $file, $memberId, $xml); $this->package->PluginRelease[] = $release; $this->package->save(); } elseif ($svn) { $dir = $this->importFromSvn($svn); $this->importSCMFile($pear, $memberId, $dir); } elseif ($gitUrl && $gitCommit) { $dir = $this->importFromGit($gitUrl, $gitCommit); $this->importSCMFile($pear, $memberId, $dir); } }
function make_tarball_and_emit($fobj, $file_list, $tarName, $compress = NULL) { if ($compress == 'gz') { $tarName .= '.gz'; } elseif ($compress == 'bz2') { $tarName .= '.bz2'; } header("Content-type: application/tarball"); header("Content-Disposition: attachment; filename={$tarName}"); $tar = new Archive_Tar($tarName, $compress); file_put_contents("php://stdout", "Tarball Created ({$tarName})\n"); foreach ($file_list as $name => $handle) { file_put_contents("php://stdout", "\t{$name} added to tarball\n"); $tar->addString($name, stream_get_contents($handle)) or die("Error adding {$name} to tarball"); } header("Content-Length: " . filesize($tarName)); $f = fopen($tarName, 'r'); while (!feof($f)) { fwrite($fobj, fgets($f)); } fclose($f); unlink($tarName); //no caching... which should be done as we scale }
/** * This method opens and validates the uploaded PEAR package * and assembles the content of the package file itself, the * dependencies and the release notes. * * @param Faett_Package_Model_Link $link The link with the PEAR package file * @return void */ public function generatePEARInfos(Faett_Package_Model_Link $link) { // initialize the PEAR service implementation $service = Faett_Core_Factory::get(Mage::getBaseDir()); // initialize the PEAR_PackageFile_v2 instance $pf = $service->packageFile($packageFile = Faett_Package_Model_Link::getBasePath() . $link->getLinkFile()); // initialize the archive $tar = new Archive_Tar($packageFile); // try to load the content of the package2.xml file $contents = $tar->extractInString('package2.xml'); // if not available, try to load from package.xml file if (!$contents) { $contents = $tar->extractInString('package.xml'); } // load the data to assemble the link with $link->setPackageFile($contents); $link->setPackageName($pf->getName()); $link->setPackageSize(filesize($packageFile)); $link->setDependencies(serialize($pf->getDependencies())); $link->setState($pf->getState()); $link->setVersion($pf->getVersion()); $link->setReleaseDate($pf->getDate()); $link->setLicence($pf->getLicense()); $link->setSummary($pf->getSummary()); $link->setDescription($pf->getDescription()); $link->setNotes($pf->getNotes()); // set the licence URI if (is_array($loc = $pf->getLicenseLocation())) { if (array_key_exists('uri', $loc)) { $link->setLicenceUri($loc['uri']); } elseif (array_key_exists('filesource', $loc)) { $link->setLicenceUri($loc['filesource']); } } // save the completed link $link->save(); }
function stepUnpack(Am_BatchProcessor $batch) { foreach ($this->getSession()->upgrades as $k => $upgrade) { $upgrade->dir = null; if (!empty($upgrade->dir)) { continue; } // already unpacked? $record = $this->getDi()->uploadTable->load($upgrade->upload_id); $tar = new Archive_Tar($fn = $record->getFullPath()); $upgrade->dir = DATA_DIR . DIRECTORY_SEPARATOR . $record->getFilename() . '-unpack'; if (!mkdir($upgrade->dir)) { throw new Am_Exception_InputError("Could not create folder to unpack downloaded archive: [{$upgrade->dir}]"); unset($upgrade->dir); } $tar->setErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_tarError')); try { if (!$tar->extract($upgrade->dir)) { throw new Am_Exception_InputError("Could not unpack downloaded archive: [{$fn}] to [{$upgrade->dir}]"); } } catch (Exception $e) { $this->getDi()->errorLogTable->logException($e); unset($upgrade->dir); @rmdir($upgrade->dir); } // normally we delete uploaded archive $record->delete(); unset($upgrade->upload_id); } return true; }