public static function getPackage($url, $version) { self::$package = App::getBackupBase() . $version; if (preg_match('/\\.zip$/i', $url)) { $type = '.zip'; } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) { $type = '.tgz'; } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) { $type = '.tar.bz2'; } else { throw new \Exception('Unable to extract package ' . $url . ': unknown format'); } self::$package = self::$package . $type; try { // Reuse already downloaded package if (!file_exists(self::$package)) { if (self::fetch($url) === false) { throw new \Exception("Error storing package content"); } App::log('Downloaded ' . filesize(self::$package) . ' bytes.', \OCP\Util::DEBUG); } else { App::log('Use already downloaded package ' . self::$package . '. Size is ' . filesize(self::$package) . ' bytes.', \OCP\Util::DEBUG); } $extractDir = self::getPackageDir($version); Helper::mkdir($extractDir, true); $archive = \OC_Archive::open(self::$package); if (!$archive || !$archive->extract($extractDir)) { throw new \Exception(self::$package . " extraction error"); } } catch (\Exception $e) { App::log('Retrieving ' . $url); self::cleanUp($version); throw $e; } // Prepare extracted data // to have '3rdparty', 'apps' and 'core' subdirectories $baseDir = $extractDir . '/' . self::PACKAGE_ROOT; if (!file_exists($baseDir)) { App::log('Expected fresh sources in ' . $baseDir . '. Nothing is found. Something is wrong with OC_Archive.'); App::log($extractDir . ' content: ' . implode(' ', scandir($extractDir))); if ($type === '.zip' && !extension_loaded('zip')) { $hint = App::$l10n->t('Please ask your server administrator to enable PHP zip extension.'); } throw new \Exception(self::$package . " extraction error. " . $hint); } include $baseDir . '/version.php'; Helper::checkVersion($OC_Version, $OC_VersionString); $sources = Helper::getSources($version); rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]); rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]); rename($baseDir, $sources[Helper::CORE_DIRNAME]); }
public static function getPackage($url, $version) { self::$package = \OC_Helper::tmpFile(); if (!self::$package) { throw new \Exception('Unable to create a temporary file'); } try { if (file_put_contents(self::$package, self::fetch($url)) === false) { throw new \Exception("Error storing package content"); } if (preg_match('/\\.zip$/i', $url)) { rename(self::$package, self::$package . '.zip'); self::$package .= '.zip'; } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) { rename(self::$package, self::$package . '.tgz'); self::$package .= '.tgz'; } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) { rename(self::$package, self::$package . '.tar.bz2'); self::$package .= '.tar.bz2'; } else { throw new \Exception('Unable to extract package'); } $extractDir = self::getPackageDir($version); Helper::mkdir($extractDir, true); $archive = \OC_Archive::open(self::$package); if (!$archive || !$archive->extract($extractDir)) { throw new \Exception(self::$package . " extraction error"); } } catch (\Exception $e) { App::log('Retrieving ' . $url); self::cleanUp($version); throw $e; } Helper::removeIfExists(self::$package); // Prepare extracted data // to have '3rdparty', 'apps' and 'core' subdirectories $sources = Helper::getSources($version); $baseDir = $extractDir . '/' . self::PACKAGE_ROOT; @rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]); @rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]); @rename($baseDir, $sources[Helper::CORE_DIRNAME]); }
public static function getPackage($url, $version) { self::$package = \OC_Helper::tmpFile(); try { if (!copy($url, self::$package)) { throw new \Exception("Failed to download {$url} package"); } if (preg_match('/\\.zip$/i', $url)) { rename(self::$package, self::$package . '.zip'); self::$package .= '.zip'; } elseif (preg_match('/(\\.tgz|\\.tar\\.gz)$/i', $url)) { rename(self::$package, self::$package . '.tgz'); self::$package .= '.tgz'; } elseif (preg_match('/\\.tar\\.bz2$/i', $url)) { rename(self::$package, self::$package . '.tar.bz2'); self::$package .= '.tar.bz2'; } else { throw new \Exception('Unable to extract package'); } $extractDir = self::getPackageDir($version); Helper::mkdir($extractDir, true); $archive = \OC_Archive::open(self::$package); if ($archive) { $archive->extract($extractDir); } else { throw new \Exception(self::$package . " extraction error"); } } catch (\Exception $e) { self::cleanUp($version); throw $e; } Helper::removeIfExists(self::$package); // Prepare extracted data // to have '3rdparty', 'apps' and 'core' subdirectories $sources = Helper::getSources($version); $baseDir = $extractDir . '/' . self::PACKAGE_ROOT; @rename($baseDir . '/' . Helper::THIRDPARTY_DIRNAME, $sources[Helper::THIRDPARTY_DIRNAME]); @rename($baseDir . '/' . Helper::APP_DIRNAME, $sources[Helper::APP_DIRNAME]); @rename($baseDir, $sources[Helper::CORE_DIRNAME]); }