Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #408: Support proxies #440

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/Plugin/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Composer\Script\ScriptEvents;
use Composer\Installer\PackageEvent;
use Composer\Util\ProcessExecutor;
use Composer\Util\RemoteFilesystem;
use Composer\Util\HttpDownloader;
use cweagans\Composer\Capability\ResolverProvider;
use cweagans\Composer\PatchCollection;
use cweagans\Composer\Resolvers\ResolverBase;
Expand Down Expand Up @@ -314,7 +314,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 @@ -373,12 +373,12 @@ 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
* @throws \Exception
*/
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url)
protected function getAndApplyPatch(HttpDownloader $downloader, $install_path, $patch_url)
{

// Local patch file.
Expand All @@ -388,15 +388,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, []);
} 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, []);
}
}

Expand Down