public function fetch($version, $destination)
 {
     array_walk($this->filenames, function ($filename) use($version, $destination) {
         $url = $this->getUri($filename, $version);
         $this->fs->ensureDirectoryExists($destination . '/' . dirname($filename));
         $this->remoteFilesystem->copy($url, $url, $destination . '/' . $filename);
     });
 }
 /**
  * @static
  *
  * @param \Composer\IO\IOInterface $io
  * @param string                   $destination
  *
  * @return bool
  */
 private static function download(\Composer\IO\IOInterface $io, $destination)
 {
     $io->write('<info>Installing jackrabbit</info>');
     if (false === ($urls = self::getDownloadUrl())) {
         $io->write('Invalid URLs');
     } else {
         reset($urls);
         $r = new RemoteFilesystem($io);
         do {
             try {
                 $url = current($urls);
                 $file = $destination . '/' . basename(parse_url($url, PHP_URL_PATH));
                 $io->write(sprintf('Retrieving Jackrabbit from "%s"', $url), true);
                 $result = $r->copy('', $url, $file, true);
             } catch (\Composer\Downloader\TransportException $ex) {
                 $io->write('', true);
                 $result = false;
                 $file = null;
             }
         } while (false === $result && next($urls));
         if (is_null($file)) {
             throw new \Exception('Invalid file name');
         }
         return $file;
     }
     return false;
 }
Esempio n. 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rfs = new RemoteFilesystem($this->getIO());
     $latest = trim($rfs->getContents('getcomposer.org', 'http://getcomposer.org/version', false));
     if (Composer::VERSION !== $latest) {
         $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));
         $remoteFilename = 'http://getcomposer.org/composer.phar';
         $localFilename = $_SERVER['argv'][0];
         $tempFilename = basename($localFilename, '.phar') . '-temp.phar';
         $rfs->copy('getcomposer.org', $remoteFilename, $tempFilename);
         try {
             chmod($tempFilename, 0777 & ~umask());
             // test the phar validity
             $phar = new \Phar($tempFilename);
             // free the variable to unlock the file
             unset($phar);
             rename($tempFilename, $localFilename);
         } catch (\Exception $e) {
             @unlink($tempFilename);
             if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
                 throw $e;
             }
             $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>');
             $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         }
     } else {
         $output->writeln("<info>You are using the latest composer version.</info>");
     }
 }
Esempio n. 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
     $config = Factory::createConfig();
     $remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
     $cacheDir = $config->get('cache-dir');
     $rollbackDir = $config->get('home');
     $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
     // check if current dir is writable and if not try the cache dir from settings
     $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
     // check for permissions in local filesystem before start connection process
     if (!is_writable($tmpDir)) {
         throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
     }
     if (!is_writable($localFilename)) {
         throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written');
     }
     if ($input->getOption('rollback')) {
         return $this->rollback($output, $rollbackDir, $localFilename);
     }
     $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false));
     $updateVersion = $input->getArgument('version') ?: $latestVersion;
     if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
         $output->writeln('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
         return 1;
     }
     if (Composer::VERSION === $updateVersion) {
         $output->writeln('<info>You are already using composer version ' . $updateVersion . '.</info>');
         return 0;
     }
     $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
     $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
     $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
     $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename);
     if (!file_exists($tempFilename)) {
         $output->writeln('<error>The download of the new composer version failed for an unexpected reason</error>');
         return 1;
     }
     // remove saved installations of composer
     if ($input->getOption('clean-backups')) {
         $finder = $this->getOldInstallationFinder($rollbackDir);
         $fs = new Filesystem();
         foreach ($finder as $file) {
             $file = (string) $file;
             $output->writeln('<info>Removing: ' . $file . '</info>');
             $fs->remove($file);
         }
     }
     if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
         $output->writeln('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
     if (file_exists($backupFile)) {
         $output->writeln('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
     } else {
         $output->writeln('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
     }
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function download(PackageInterface $package, $path)
 {
     $url = $package->getDistUrl();
     if (!$url) {
         throw new \InvalidArgumentException('The given package is missing url information');
     }
     if (!is_dir($path)) {
         if (file_exists($path)) {
             throw new \UnexpectedValueException($path . ' exists and is not a directory');
         }
         if (!mkdir($path, 0777, true)) {
             throw new \UnexpectedValueException($path . ' does not exist and could not be created');
         }
     }
     $fileName = $this->getFileName($package, $path);
     $this->io->write("  - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
     $url = $this->processUrl($url);
     $rfs = new RemoteFilesystem($this->io);
     $rfs->copy($package->getSourceUrl(), $url, $fileName);
     $this->io->write('');
     if (!file_exists($fileName)) {
         throw new \UnexpectedValueException($url . ' could not be saved to ' . $fileName . ', make sure the' . ' directory is writable and you have internet connectivity');
     }
     $checksum = $package->getDistSha1Checksum();
     if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
         throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from ' . $url . ')');
     }
     $this->io->write('');
 }
Esempio n. 6
0
 public function testCopy()
 {
     $fs = new RemoteFilesystem($this->getMock('Composer\\IO\\IOInterface'));
     $file = tempnam(sys_get_temp_dir(), 'c');
     $this->assertTrue($fs->copy('http://example.org', 'file://' . __FILE__, $file));
     $this->assertFileExists($file);
     $this->assertContains('testCopy', file_get_contents($file));
     unlink($file);
 }
Esempio n. 7
0
 /**
  * {@inheritDoc}
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  *
  * @throws FilesystemException When the temporary directory or local file are not writable.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $originName = $this->getOriginName();
     $config = Factory::createConfig();
     $inputOutput = $this->getIO();
     $this->rfs = new RemoteFilesystem($inputOutput, $config);
     $cacheDir = $config->get('cache-dir');
     $rollbackDir = $config->get('home');
     $localFilename = $this->determineLocalFileName();
     // check if current dir is writable and if not try the cache dir from settings
     $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
     // check for permissions in local filesystem before start connection process
     if (!is_writable($tmpDir)) {
         throw new FilesystemException(sprintf('Self update failed: the "%s" directory used to download the temp file could not be written', $tmpDir));
     }
     if (!is_writable($localFilename)) {
         throw new FilesystemException('Self update failed: "' . $localFilename . '" is not writable.');
     }
     if ($input->getOption('rollback')) {
         return $this->rollback($rollbackDir, $localFilename);
     }
     $latestVersion = $this->getLatestVersion();
     $updateVersion = $input->getArgument('version') ?: $latestVersion;
     if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
         $inputOutput->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
         return 1;
     }
     if (Tenside::VERSION === $updateVersion) {
         $inputOutput->writeError('<info>You are already using version ' . $updateVersion . '.</info>');
         return 0;
     }
     $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
     $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Tenside::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Tenside::VERSION), self::OLD_INSTALL_EXT);
     $inputOutput->writeError(sprintf('Updating to version <info>%s</info>.', $updateVersion));
     $remoteFilename = $this->determineRemoteFilename($updateVersion);
     $this->rfs->copy($originName, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
     if (!file_exists($tempFilename)) {
         $inputOutput->writeError('<error>The download of the new version failed for an unexpected reason</error>');
         return 1;
     }
     // remove saved installations of tenside
     if ($input->getOption('clean-backups')) {
         $this->cleanupOldBackups($rollbackDir);
     }
     if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
         $inputOutput->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
         $inputOutput->writeError('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
     if (file_exists($backupFile)) {
         $inputOutput->writeError(sprintf('Use <info>%s self-update --rollback</info> to return to version %s', $localFilename, Tenside::VERSION));
         return 0;
     }
     $inputOutput->writeError(sprintf('<warning>A backup of the current version could not be written to %s, ' . 'no rollback possible</warning>', $backupFile));
     return 0;
 }
Esempio n. 8
0
 /**
  * {@inheritDoc}
  */
 public function download(PackageInterface $package, $path)
 {
     $url = $package->getDistUrl();
     $checksum = $package->getDistSha1Checksum();
     if (!is_dir($path)) {
         if (file_exists($path)) {
             throw new \UnexpectedValueException($path . ' exists and is not a directory');
         }
         if (!mkdir($path, 0777, true)) {
             throw new \UnexpectedValueException($path . ' does not exist and could not be created');
         }
     }
     $fileName = rtrim($path . '/' . md5(time() . rand()) . '.' . pathinfo($url, PATHINFO_EXTENSION), '.');
     $this->io->write("  - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
     if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) {
         // bypass https for github if openssl is disabled
         if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) {
             $url = 'http://nodeload.' . $match[1];
         } else {
             throw new \RuntimeException('You must enable the openssl extension to download files via https');
         }
     }
     $rfs = new RemoteFilesystem($this->io);
     $rfs->copy($package->getSourceUrl(), $url, $fileName);
     $this->io->write('');
     if (!file_exists($fileName)) {
         throw new \UnexpectedValueException($url . ' could not be saved to ' . $fileName . ', make sure the' . ' directory is writable and you have internet connectivity');
     }
     if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
         throw new \UnexpectedValueException('The checksum verification of the archive failed (downloaded from ' . $url . ')');
     }
     $this->io->write('    Unpacking archive');
     $this->extract($fileName, $path);
     $this->io->write('    Cleaning up');
     unlink($fileName);
     // If we have only a one dir inside it suppose to be a package itself
     $contentDir = glob($path . '/*');
     if (1 === count($contentDir)) {
         $contentDir = $contentDir[0];
         // Rename the content directory to avoid error when moving up
         // a child folder with the same name
         $temporaryName = md5(time() . rand());
         rename($contentDir, $temporaryName);
         $contentDir = $temporaryName;
         foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
             if (trim(basename($file), '.')) {
                 rename($file, $path . '/' . basename($file));
             }
         }
         rmdir($contentDir);
     }
     $this->io->write('');
 }
 /**
  * Executes a command via CLI
  *
  * @param Console\Input\InputInterface $input
  * @param Console\Output\OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $tempFolder = $input->getOption('temp-folder');
     $destinationFolder = $input->getOption('src-destination');
     if (empty($destinationFolder)) {
         $destinationFolder = realpath(__DIR__ . '/../../../../');
     }
     if (!is_writable($destinationFolder)) {
         $output->writeln('Chash update failed: the "' . $destinationFolder . '" directory used to update the Chash file could not be written');
         return 0;
     }
     if (!is_writable($tempFolder)) {
         $output->writeln('Chash update failed: the "' . $tempFolder . '" directory used to download the temp file could not be written');
         return 0;
     }
     //$protocol = extension_loaded('openssl') ? 'https' : 'http';
     $protocol = 'http';
     $rfs = new RemoteFilesystem(new NullIO());
     // Chamilo version
     //$latest = trim($rfs->getContents('version.chamilo.org', $protocol . '://version.chamilo.org/version.php', false));
     //https://github.com/chamilo/chash/archive/master.zip
     $tempFile = $tempFolder . '/chash-master.zip';
     $rfs->copy('github.com', 'https://github.com/chamilo/chash/archive/master.zip', $tempFile);
     if (!file_exists($tempFile)) {
         $output->writeln('Chash update failed: the "' . $tempFile . '" file could not be written');
         return 0;
     }
     $folderPath = $tempFolder . '/chash';
     if (!is_dir($folderPath)) {
         mkdir($folderPath);
     }
     $zippy = Zippy::load();
     $archive = $zippy->open($tempFile);
     try {
         $archive->extract($folderPath);
     } catch (\Alchemy\Zippy\Exception\RunTimeException $e) {
         $output->writeln("<comment>Chash update failed during unzip.");
         $output->writeln($e->getMessage());
         return 0;
     }
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror($folderPath . '/chash-master', $destinationFolder, null, array('override' => true));
     $output->writeln('Copying ' . $folderPath . '/chash-master to ' . $destinationFolder);
 }
Esempio n. 10
0
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
        $tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar';
        // check for permissions in local filesystem before start connection process
        if (!is_writable($tempDirectory = dirname($tempFilename))) {
            throw new FilesystemException('imi-conrun update failed: the "' . $tempDirectory . '" directory used to download the temp file could not be written');
        }
        if (!is_writable($localFilename)) {
            throw new FilesystemException('imi-conrun update failed: the "' . $localFilename . '" file could not be written');
        }
        $io = new ConsoleIO($input, $output, $this->getHelperSet());
        $rfs = new RemoteFilesystem($io);
        $loadUnstable = $input->getOption('unstable');
        if ($loadUnstable) {
            $versionTxtUrl = 'https://raw.githubusercontent.com/iMi-digital/imi-conrun/develop/version.txt';
            $remoteFilename = 'https://raw.githubusercontent.com/iMi-digital/imi-conrun/develop/imi-conrun.phar';
        } else {
            $versionTxtUrl = 'https://raw.githubusercontent.com/iMi-digital/imi-conrun/master/version.txt';
            $remoteFilename = 'https://raw.githubusercontent.com/iMi-digital/imi-conrun/master/imi-conrun.phar';
        }
        $latest = trim($rfs->getContents('raw.githubusercontent.com', $versionTxtUrl, false));
        if ($this->getApplication()->getVersion() !== $latest || $loadUnstable) {
            $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));
            $rfs->copy('raw.github.com', $remoteFilename, $tempFilename);
            if (!file_exists($tempFilename)) {
                $output->writeln('<error>The download of the new imi-conrun version failed for an unexpected reason');
                return 1;
            }
            try {
                \error_reporting(E_ALL);
                // supress notices
                @chmod($tempFilename, 0777 & ~umask());
                // test the phar validity
                $phar = new \Phar($tempFilename);
                // free the variable to unlock the file
                unset($phar);
                @rename($tempFilename, $localFilename);
                $output->writeln('<info>Successfully updated imi-conrun</info>');
                if ($loadUnstable) {
                    $changeLogContent = $rfs->getContents('raw.github.com', 'https://raw.github.com/netz98/imi-conrun/develop/changes.txt', false);
                } else {
                    $changeLogContent = $rfs->getContents('raw.github.com', 'https://raw.github.com/netz98/imi-conrun/master/changes.txt', false);
                }
                if ($changeLogContent) {
                    $output->writeln($changeLogContent);
                }
                if ($loadUnstable) {
                    $unstableFooterMessage = <<<UNSTABLE_FOOTER
<comment>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! DEVELOPMENT VERSION. DO NOT USE IN PRODUCTION !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
</comment>
UNSTABLE_FOOTER;
                    $output->writeln($unstableFooterMessage);
                }
                $this->_exit();
            } catch (\Exception $e) {
                @unlink($tempFilename);
                if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
                    throw $e;
                }
                $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>');
                $output->writeln('<error>Please re-run the self-update command to try again.</error>');
            }
        } else {
            $output->writeln("<info>You are using the latest imi-conrun version.</info>");
        }
    }
Esempio n. 11
0
 /**
  * Apply a patch on code in the specified directory.
  *
  * @param RemoteFilesystem $downloader
  * @param $install_path
  * @param $patch_url
  * @throws \Exception
  */
 protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url)
 {
     // Local patch file.
     if (file_exists($patch_url)) {
         $filename = realpath($patch_url);
     } else {
         // Generate random (but not cryptographically so) filename.
         $filename = uniqid("/tmp/") . ".patch";
         // Download file from remote filesystem to this location.
         $hostname = parse_url($patch_url, PHP_URL_HOST);
         $downloader->copy($hostname, $patch_url, $filename, FALSE);
     }
     // Modified from drush6:make.project.inc
     $patched = FALSE;
     // The order here is intentional. p1 is most likely to apply with git apply.
     // p0 is next likely. p2 is extremely unlikely, but for some special cases,
     // it might be useful.
     $patch_levels = array('-p1', '-p0', '-p2');
     foreach ($patch_levels as $patch_level) {
         $checked = $this->executeCommand('cd %s && GIT_DIR=. git apply --check %s %s', $install_path, $patch_level, $filename);
         if ($checked) {
             // Apply the first successful style.
             $patched = $this->executeCommand('cd %s && GIT_DIR=. git apply %s %s', $install_path, $patch_level, $filename);
             break;
         }
     }
     // In some rare cases, git will fail to apply a patch, fallback to using
     // the 'patch' command.
     if (!$patched) {
         foreach ($patch_levels as $patch_level) {
             // --no-backup-if-mismatch here is a hack that fixes some
             // differences between how patch works on windows and unix.
             if ($patched = $this->executeCommand("patch %s --no-backup-if-mismatch -d %s < %s", $patch_level, $install_path, $filename)) {
                 break;
             }
         }
     }
     // Clean up the temporary patch file.
     if (isset($hostname)) {
         unlink($filename);
     }
     // If the patch *still* isn't applied, then give up and throw an Exception.
     // Otherwise, let the user know it worked.
     if (!$patched) {
         throw new \Exception("Cannot apply patch {$patch_url}");
     }
 }
 /**
  * Copy the remote file in local
  *
  * Use $acfFileUrl instead of the provided $fileUrl
  *
  * @param string $originUrl The origin URL
  * @param string $fileUrl   The file URL (ignored)
  * @param string $fileName  the local filename
  * @param bool   $progress  Display the progression
  * @param array  $options   Additional context options
  *
  * @return bool true
  */
 public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = [])
 {
     return parent::copy($originUrl, $this->wpmFileUrl, $fileName, $progress, $options);
 }