From 65bdd70eac806915f646835f6f0948f14a869bfe Mon Sep 17 00:00:00 2001 From: Jingsheng Wang Date: Fri, 20 Jan 2023 20:49:08 +0800 Subject: [PATCH] replace streamer with a downloader to support socks5 cweagans/composer-patches#408 --- src/Plugin/Patches.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Plugin/Patches.php b/src/Plugin/Patches.php index 0c4120b1..42463ffa 100644 --- a/src/Plugin/Patches.php +++ b/src/Plugin/Patches.php @@ -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; @@ -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(); @@ -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. @@ -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, []); } }