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); }
public function addToArchive(Archive_Tar $archive) { // Add top level package manifest $archive->addString('package.json', $this->toString('json')); // Normal stuff parent::addToArchive($archive); }
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')); }
/** * 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')); }
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 }
function db2app__process($values) { require_once 'Archive/Tar.php'; $tarpath = tempnam('/tmp', strval($values['database_name'])); //echo $tarpath; $compression = 'gz'; $archive = new Archive_Tar($tarpath, $compression); $path = strval($values['database_name']); $archive->addString($path . '/.htaccess', '<FilesMatch "\\.ini$"> Deny from all </FilesMatch>'); $archive->addString($path . '/Web.config', file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'site_skeleton' . DIRECTORY_SEPARATOR . 'Web.config')); mysql_select_db($values['database_name'], db()); $res = mysql_query('show tables', db()); if (!$res) { trigger_error(mysql_error(db()), E_USER_ERROR); } $tables = array(); while ($row = mysql_fetch_row($res)) { if ($row[0][0] == '_') { continue; } if (strpos($row[0], 'dataface_') === 0) { continue; } if (preg_match('/__history$/', $row[0])) { continue; } $tables[] = $row[0] . ' = "' . ucwords(str_replace('_', ' ', $row[0])) . '"'; } $archive->addString($path . '/conf.ini', ';;Configuration settings for application title="' . addslashes($values['database_name']) . '" [_database] host="' . DB_HOST . '" name="' . addslashes($values['database_name']) . '" user="******" password="******" [_tables] ' . implode("\n", $tables) . ' '); $archive->addString($path . '/index.php', '<?php //Main Application access point require_once "' . addslashes(dirname(__FILE__) . '/dataface-public-api.php') . '"; df_init(__FILE__, "' . addslashes(dirname($_SERVER['PHP_SELF'])) . '"); $app =& Dataface_Application::getInstance(); $app->display(); '); switch ($values['install_type']) { case 'ftp_install': //echo 'here'; require_once 'install/FTPExtractor.class.php'; $extractor = new FTPExtractor($archive); $res = $extractor->connect($values['ftp_host'], $values['ftp_username'], $values['ftp_password']); if (PEAR::isError($res)) { die($res->getMessage()); } $res = $extractor->extract($values['ftp_path'], '/'); //if ( PEAR::isError($res) ){ // die($res->getMessage()); //} $context = array(); if (PEAR::isError($res)) { $context['result'] = 'Error: ' . $res->getMessage(); } else { $context = $res; } include 'install' . DIRECTORY_SEPARATOR . 'archive2app-results.inc.php'; exit; default: // download_tarball //$tarpath = $_FILES['archive']['tmp_name']; if ($compression == 'gz') { $mimetype = 'application/x-gzip'; } else { $mimetype = 'application/x-tar'; } header('Content-type: ' . $mimetype); header('Content-Disposition: attachment; filename="' . basename($tarpath) . '.tar.gz"'); echo file_get_contents($tarpath); exit; } //return $tarpath; }
public function addToArchive(Archive_Tar $archive) { // Add package file $rval = $archive->addString('application' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . $this->getKey() . '.json', $this->toString('json')); if ($archive->isError($rval)) { throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage()); } // Add internal structure if ($this->getAddDirectoryToArchive()) { $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()); } } else { foreach ($this->getStructure() as $key => $value) { if ($this->_jitInstantiation && is_array($value) && !empty($value['type'])) { $class = 'Engine_Package_Manifest_Entity_' . ucfirst($value['type']); Engine_Loader::loadClass($class); $value = new $class($value); $value->setBasePath($this->getBasePath()); } else { if (!$value instanceof Engine_Package_Manifest_Entity_Abstract) { throw new Engine_Package_Manifest_Exception('Not a package entity'); } } if (method_exists($value, 'setAddDirectoryToArchive')) { $value->setAddDirectoryToArchive($this->getAddDirectoryToArchive()); } $value->addToArchive($archive); } } }
function createPatch($updatecache = false) { include_once "Lib/Archive/Tar.php"; include_once 'Lib/Text/Diff.php'; include_once 'Lib/Text/Diff/Renderer/unified.php'; $start = microtime(true); $tar_object = new Archive_Tar(_bmoddir . "Data/Cache.tar"); $tar_object->setErrorHandling(PEAR_ERROR_PRINT); $tardata = $tar_object->listContent(); $working = checkDir2(""); $fmerged = array_merge($tardata, $working); $tarf_db = reIndexByFile($tardata); $work_db = reIndexByFile($working); $workidx = indexFilename($working); $tar_idx = indexFilename($tardata); $f_names = array_unique(array_merge($workidx, $tar_idx)); $out = ""; foreach ($f_names as $file) { //speed optimization if ($tarf_db[$file] && $work_db[$file] && $tarf_db[$file]["mtime"] == $work_db[$file]["mtime"] && $updatecache != true) { continue; } if ($tarf_db[$file]) { $fts1 = $tarf_db[$file]["mtime"]; $fdata = $tar_object->extractInString($file); $lines1 = explode("\n", $fdata); //$lines1 = file("Data/$file"); if (substr($fdata, -1, 1) == "\n") { //$lines1[] = ""; } } else { $fts1 = 0; $lines1 = array(); } if ($work_db[$file]) { $fts2 = $work_db[$file]["mtime"]; //$lines2 = file(_bpatdir."$file"); $filetext = file_get_contents(_bmoddir . _bpatdir . "{$file}"); $lines2 = explode("\n", $filetext); } else { $fts2 = 0; $lines2 = array(); $filetext = ""; } if (array_search($file, $workidx) === false && array_search($file, $tar_idx) !== false) { //delted file $out .= renderHeader($file, $fts1, $fts2); $out .= "@@ -0,0 @@\n\n"; continue; } if (array_search($file, $workidx) !== false && array_search($file, $tar_idx) === false) { //added file } if ($filetext == $fdata) { continue; } $diff = new Text_Diff('auto', array($lines1, $lines2)); $renderer = new Text_Diff_Renderer_unified(); $render = $renderer->render($diff); if ($render != "") { $out .= renderHeader($file, $fts1, $fts2); //get ts to work! $out .= $render . "\n"; if (substr($filetext, -1, 1) != "\n") { $out .= "\\ No newline at end of file\n\n"; } } } if ($updatecache == true) { $tar_object->create(array()); foreach ($f_names as $file) { $tar_object->addString($file, file_get_contents(_bmoddir . _bpatdir . "{$file}")); } } return array(microtime(true) - $start, $out, count($addlist)); }
public function createAction() { // Require require_once 'PEAR.php'; require_once 'Archive/Tar.php'; // Form $this->view->form = $form = new Install_Form_Backup_Create(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Process set_time_limit(0); $values = $form->getValues(); // Make filename $archiveFileName = $values['name']; $archiveFileName = preg_replace('/[^a-zA-Z0-9_.-]/', '', $archiveFileName); if (strtolower(substr($archiveFileName, -4)) != '.tar') { $archiveFileName .= '.tar'; } $archiveFileName = $this->_outputPath . DIRECTORY_SEPARATOR . $archiveFileName; // setup paths $archiveSourcePath = APPLICATION_PATH; $tmpPath = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; // Make archive $archive = new Archive_Tar($archiveFileName); // Add files $path = $archiveSourcePath; $files = array(); $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($it as $file) { $pathname = $file->getPathname(); if ($file->isFile()) { if (substr($pathname, 0, strlen($tmpPath)) == $tmpPath) { continue; } else { $files[] = $pathname; } } } $ret = $archive->addModify($files, '', $path); if (PEAR::isError($ret)) { throw new Engine_Exception($ret->getMessage()); } // Add temporary structure only /* $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmpPath), RecursiveIteratorIterator::SELF_FIRST); foreach( $it as $file ) { if( $file->isFile() ) { continue; } else { $path = str_replace(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary' . DIRECTORY_SEPARATOR, '', $file->getPathname()); $path .= DIRECTORY_SEPARATOR . 'index.html'; $archive->addString($path, ''); } } * */ // Export database $dbTempFile = $this->_createTemporaryFile(); $db = Zend_Registry::get('Zend_Db'); $export = Engine_Db_Export::factory($db, array()); $this->_export = $export; $export->write($dbTempFile); $archive->addString('database.sql', file_get_contents($dbTempFile)); unlink($dbTempFile); return $this->_helper->redirector->gotoRoute(array('action' => 'index')); }
if ($sections[0] == 'work') { $tar->addString('jxlib' . DS . implode(DS, $sections), file_get_contents($file)); } } break; case 'bz2': require_once 'includes/Tar.php'; $fileName = "jxlib.tar.bz2"; $archiveSubPath .= DS . $fileName; $archiveName = $work_dir . $archiveSubPath; $tar = new Archive_Tar($archiveName, 'bz2'); $includedPic = false; foreach ($filesToArchive as $file) { $sections = explode(DS, $file); if ($sections[0] == 'work') { $tar->addString('jxlib' . DS . implode(DS, $sections), file_get_contents($file)); } } break; } /** //remove the files from the server foreach ($filesToArchive as $file){ $sections = explode(DS,$file); if ($sections[0] == 'work'){ unlink($file); } } */ //setup the return object to send via JSON $obj = new stdClass();
/** * Creates an archive. */ public static function archiveNodes($nodes, $aname, $fake = false) { // -1: empty folder $files = array(); if (is_array($nodes)) { // check integrity $strings = 0; // 1 - strings; 2 - arrays foreach ($nodes as $node) { $strings = is_string($node) ? $strings + 1 : $strings - 1; } if ($strings > 0 && $strings != count($nodes)) { return false; } if ($strings == count($nodes)) { foreach ($nodes as $node) { // if is directory if (is_dir($node)) { self::importFilesFromDir(rtrim($node, '/*') . '/*', basename($node) . '/', true, $files); } else { if (is_file($node)) { $files[basename($node)] = $node; } } } } else { // make files list foreach ($nodes as $node) { if (is_array($node)) { $node = (object) $node; } // put directory inside another directory in archive if (substr($node->source, -1) == '/') { if (substr($node->destination, -1) != '/') { return false; } if (!isset($node->recursive) || !$node->recursive) { self::importFilesFromDir($node->source . '*', $node->destination . basename($node->source) . '/', false, $files); } else { self::importFilesFromDir($node->source . '*', $node->destination . basename($node->source) . '/', true, $files); } } elseif (substr($node->source, -1) == '*') { if (substr($node->destination, -1) != '/') { return false; } if (!isset($node->recursive) || !$node->recursive) { self::importFilesFromDir($node->source, $node->destination, false, $files); } else { self::importFilesFromDir($node->source, $node->destination, true, $files); } } else { // put regular file inside directory in archive if (!is_file($node->source)) { return false; } $files[$node->destination] = $node->source; } } } } elseif (is_string($nodes)) { // if is directory if (is_dir($nodes)) { self::importFilesFromDir(rtrim($nodes, '/*') . '/*', '/', true, $files); } else { if (is_file($nodes)) { $files[basename($nodes)] = $nodes; } } } // fake creation: return archive data if ($fake) { $totalSize = 0; foreach ($files as $fn) { $totalSize += filesize($fn); } return array('totalSize' => $totalSize, 'numberOfFiles' => count($files), 'files' => $files); } $ext = strtolower(pathinfo($aname, PATHINFO_EXTENSION)); if ($ext == 'zip') { $atype = self::ZIP; } else { if ($ext == 'rar') { $atype = self::RAR; } else { if ($ext == 'tar' || preg_match('~\\.tar\\.(gz|bz2|xz|Z)$~', $aname)) { $atype = self::TAR; } else { if ($ext == 'gz') { $atype = self::GZIP; } else { return false; } } } } switch ($atype) { case self::ZIP: $zip = new \ZipArchive(); $result = $zip->open($aname, \ZIPARCHIVE::CREATE); if ($result !== true) { throw new \Exception('ZipArchive error: ' . $result); } foreach ($files as $localname => $filename) { /*echo "added ".$filename.PHP_EOL; echo number_format(filesize($filename)).PHP_EOL; */ if (is_null($filename)) { if ($zip->addEmptyDir($localname) === false) { return false; } } else { if ($zip->addFile($filename, $localname) === false) { return false; } } } $zip->close(); return count($files); break; case self::RAR: return false; break; case self::TAR: $compression = null; switch (strtolower(pathinfo($aname, PATHINFO_EXTENSION))) { case 'gz': $compression = 'gz'; break; case 'bz2': $compression = 'bz2'; break; case 'xz': $compression = 'lzma2'; break; case 'Z': $tar_aname = 'compress.lzw://' . $aname; break; } if (isset($tar_aname)) { $tar = new \Archive_Tar($tar_aname, $compression); } else { $tar = new \Archive_Tar($aname, $compression); } foreach ($files as $localname => $filename) { $remove_dir = dirname($filename); $add_dir = dirname($localname); /*echo "added ".$filename.PHP_EOL; echo number_format(filesize($filename)).PHP_EOL; */ if (is_null($filename)) { if ($tar->addString($localname, "") === false) { return false; } } else { if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { return false; } } } $tar = null; return count($files); break; case self::GZIP: if (count($files) > 1) { return false; } /*if ($localname != basename($aname, '.gz')) return false; */ $filename = array_shift($files); if (is_null($filename)) { return false; } // invalid list if (file_put_contents($aname, gzencode(file_get_contents($filename))) !== false) { return 1; } else { return false; } break; } }
usage("Could not create tar {$archive} in {$archive_dir}"); } foreach ($existing as $l_mod => $file) { if (!array_key_exists($l_mod, $launchpad_modules)) { I2CE::raiseError("The module {$l_mod} has a .pot files but is not a module in the system -- skipping"); continue; } if (!$tar->addModify($file, $l_mod, dirname($file))) { usage("Could not add {$file}"); } unset($launchpad_modules[$l_mod]); } if (count($launchpad_modules) > 0) { I2CE::raiseError("The following:\n\t" . implode(",", array_keys($launchpad_modules)) . "\ndid not have an existing .po file. Creating a blank one"); } foreach ($launchpad_modules as $l_mod => $top_mod) { $po = loadPOT(getcwd() . DIRECTORY_SEPARATOR . $template_dir . DIRECTORY_SEPARATOR . $l_mod . DIRECTORY_SEPARATOR . $l_mod . '.pot'); if (!is_array($po) || count($po) < 1) { //I2CE::raiseError("Problem with .pot for $l_mod. Skipping"); no translations continue; } $cs = $po['']['comments']['']; array_unshift($cs, "{$locale} translation for " . $basename); $po['']['comments'][''] = $cs; $po = createPOT($top_mod, $l_mod, false, $po); if (!$tar->addString($l_mod . DIRECTORY_SEPARATOR . $locale . '.po', $po)) { I2CE::raiseError("Could not add untranslated {$l_mod}"); } } I2CE::raiseError("Created {$archive} in {$archive_dir}"); }