Skip to content

Commit

Permalink
Fix #408: Support proxies (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Jan 26, 2023
1 parent f403f94 commit 37e1b29
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Composer\Script\ScriptEvents;
use Composer\Installer\PackageEvent;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\Util\HttpDownloader;
use Symfony\Component\Process\Process;

class Patches implements PluginInterface, EventSubscriberInterface {
Expand Down Expand Up @@ -309,7 +309,7 @@ public function postInstall(PackageEvent $event) {
$install_path = $manager->getInstaller($package->getType())->getInstallPath($package);

// Set up a downloader.
$downloader = new RemoteFilesystem($this->io, $this->composer->getConfig());
$downloader = new HttpDownloader($this->io, $this->composer->getConfig());

// Track applied patches in the package info in installed.json
$localRepository = $this->composer->getRepositoryManager()->getLocalRepository();
Expand Down Expand Up @@ -365,13 +365,13 @@ protected function getPackageFromOperation(OperationInterface $operation) {
/**
* Apply a patch on code in the specified directory.
*
* @param RemoteFilesystem $downloader
* @param HttpDownloader $downloader
* @param $install_path
* @param $patch_url
* @param PackageInterface $package
* @throws \Exception
*/
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url, PackageInterface $package) {
protected function getAndApplyPatch(HttpDownloader $downloader, $install_path, $patch_url, PackageInterface $package) {

// Local patch file.
if (file_exists($patch_url)) {
Expand All @@ -381,15 +381,12 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path,
// Generate random (but not cryptographically so) filename.
$filename = uniqid(sys_get_temp_dir().'/') . ".patch";

// Download file from remote filesystem to this location.
$hostname = parse_url($patch_url, PHP_URL_HOST);

try {
$downloader->copy($hostname, $patch_url, $filename, false);
$downloader->copy($patch_url, $filename, array());
} catch (\Exception $e) {
// In case of an exception, retry once as the download might
// have failed due to intermittent network issues.
$downloader->copy($hostname, $patch_url, $filename, false);
$downloader->copy($patch_url, $filename, array());
}
}

Expand Down

0 comments on commit 37e1b29

Please sign in to comment.