-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Improve stream wrapper support #12396
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
base: main
Are you sure you want to change the base?
Changes from 39 commits
2ab3d1e
708c809
e8a516f
198a7ea
9f03eba
ed968c0
27fac4b
d1081a3
4b5129b
21b7a7e
a23e7ce
40eb099
0cd95aa
598e88e
413dd88
d859488
7542d71
faeac42
aa70941
1430918
1baf8bd
2c9ed1f
d32e015
463cebe
32e6c08
d359604
6592d1d
95353bc
ea4e18b
59bdaec
dc204f7
6dd3cf8
8184e1e
89d71b2
8bb5b15
f3ae074
79e9bc5
5adaa86
f2db2ca
9d8b179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,18 +211,16 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Ro | |
|
|
||
| $filesystem = new Filesystem(); | ||
| $filesystem->ensureDirectoryExists($config->get('vendor-dir')); | ||
| // Do not remove double realpath() calls. | ||
| // Fixes failing Windows realpath() implementation. | ||
| // See https://bugs.php.net/bug.php?id=72738 | ||
| $basePath = $filesystem->normalizePath(realpath(realpath(Platform::getCwd()))); | ||
| $vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir')))); | ||
| $basePath = $filesystem->normalizePath(Platform::realpath(Platform::getCwd())); | ||
| $vendorPath = $filesystem->normalizePath(Platform::realpath($config->get('vendor-dir'))); | ||
| $useGlobalIncludePath = $config->get('use-include-path'); | ||
| $prependAutoloader = $config->get('prepend-autoloader') === false ? 'false' : 'true'; | ||
| $targetDir = $vendorPath.'/'.$targetDir; | ||
| $filesystem->ensureDirectoryExists($targetDir); | ||
| $targetDir = Platform::realpath($targetDir); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The preceding |
||
|
|
||
| $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); | ||
| $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true); | ||
| $vendorPathCode = $filesystem->findShortestPathCode($targetDir, $vendorPath, true); | ||
| $vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, $targetDir, true); | ||
|
|
||
| $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); | ||
| $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); | ||
|
|
@@ -493,7 +491,7 @@ private function buildExclusionRegex(string $dir, array $excluded): ?string | |
| // if $dir does not exist, it should anyway not find anything there so no trouble | ||
| if (file_exists($dir)) { | ||
| // transform $dir in the same way that exclude-from-classmap patterns are transformed so we can match them against each other | ||
| $dirMatch = preg_quote(strtr(realpath($dir), '\\', '/')); | ||
| $dirMatch = preg_quote(strtr(Platform::realpath($dir), '\\', '/')); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| foreach ($excluded as $index => $pattern) { | ||
| // extract the constant string prefix of the pattern here, until we reach a non-escaped regex special character | ||
| $pattern = Preg::replace('{^(([^.+*?\[^\]$(){}=!<>|:\\\\#-]+|\\\\[.+*?\[^\]$(){}=!<>|:#-])*).*}', '$1', $pattern); | ||
|
|
@@ -1165,10 +1163,10 @@ class ComposerStaticInit$suffix | |
|
|
||
| $filesystem = new Filesystem(); | ||
|
|
||
| $vendorPathCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/"; | ||
| $vendorPharPathCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/"; | ||
| $appBaseDirCode = ' => ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/"; | ||
| $appBaseDirPharCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/"; | ||
| $vendorPathCode = ' => ' . $filesystem->findShortestPathCode($targetDir, $vendorPath, true, true) . " . '/"; | ||
| $vendorPharPathCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode($targetDir, $vendorPath, true, true) . " . '/"; | ||
| $appBaseDirCode = ' => ' . $filesystem->findShortestPathCode($targetDir, $basePath, true, true) . " . '/"; | ||
| $appBaseDirPharCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode($targetDir, $basePath, true, true) . " . '/"; | ||
|
|
||
| $absoluteVendorPathCode = ' => ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1); | ||
| $absoluteVendorPharPathCode = ' => ' . substr(var_export(rtrim('phar://' . $vendorDir, '\\/') . '/', true), 0, -1); | ||
|
|
@@ -1291,10 +1289,12 @@ static function ($matches) use (&$updir): string { | |
| $installPath = strtr(Platform::getCwd(), '\\', '/'); | ||
| } | ||
|
|
||
| $resolvedPath = realpath($installPath . '/' . $updir); | ||
| if (false === $resolvedPath) { | ||
| try { | ||
| $resolvedPath = Platform::realpath($installPath . '/' . $updir); | ||
| } catch (\RuntimeException $e) { | ||
| continue; | ||
| } | ||
|
|
||
| $autoloads[] = preg_quote(strtr($resolvedPath, '\\', '/')) . '/' . $path . '($|/)'; | ||
| continue; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| use Composer\Cache; | ||
| use Composer\Factory; | ||
| use Composer\Util\Platform; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
@@ -67,8 +68,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
| continue; | ||
| } | ||
|
|
||
| $cachePath = realpath($cachePath); | ||
| if (!$cachePath) { | ||
| try { | ||
| $cachePath = Platform::realpath($cachePath); | ||
| } catch (\RuntimeException $e) { | ||
|
Comment on lines
+71
to
+73
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested in: 89d71b2 |
||
| $io->writeError("<info>Cache directory does not exist ($key): $cachePath</info>"); | ||
|
|
||
| continue; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,7 +189,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v | |
| if ( | ||
| ($configFile === 'composer.json' || $configFile === './composer.json') | ||
| && !file_exists($configFile) | ||
| && realpath(Platform::getCwd()) === realpath($this->config->get('home')) | ||
| && Platform::realpath(Platform::getCwd()) === Platform::realpath($this->config->get('home')) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First use:
Second use:
and throws So in both cases, Added a test in 8184e1e because there was none covering that path yet. |
||
| ) { | ||
| file_put_contents($configFile, "{\n}\n"); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -432,13 +432,15 @@ protected function installRootPackage(InputInterface $input, IOInterface $io, Co | |||||||||
|
|
||||||||||
| // handler Ctrl+C aborts gracefully | ||||||||||
| @mkdir($directory, 0777, true); | ||||||||||
| if (false !== ($realDir = realpath($directory))) { | ||||||||||
| try { | ||||||||||
| $realDir = Platform::realpath($directory); | ||||||||||
| $signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) use ($realDir) { | ||||||||||
| $this->getIO()->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG); | ||||||||||
| $fs = new Filesystem(); | ||||||||||
| $fs->removeDirectory($realDir); | ||||||||||
| $handler->exitWithLastSignal(); | ||||||||||
| }); | ||||||||||
| } catch (\RuntimeException $exception) { | ||||||||||
| } | ||||||||||
|
Comment on lines
434
to
444
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original logic is ~if we have composer/src/Composer/Command/CreateProjectCommand.php Lines 489 to 492 in 79e9bc5
Now if I guess the signal handler intercepts ctrl-c etc to delete the directory before exiting, so it's not needed if there is no directory to delete. |
||||||||||
|
|
||||||||||
| // avoid displaying 9999999-dev as version if default-branch was selected | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| use Composer\Repository\RepositoryFactory; | ||
| use Composer\Spdx\SpdxLicenses; | ||
| use Composer\Util\Filesystem; | ||
| use Composer\Util\Platform; | ||
| use Composer\Util\Silencer; | ||
| use Symfony\Component\Console\Input\ArrayInput; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
|
|
@@ -181,10 +182,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
| } | ||
|
|
||
| if ($input->isInteractive() && is_dir('.git')) { | ||
| $ignoreFile = realpath('.gitignore'); | ||
|
|
||
| if (false === $ignoreFile) { | ||
| $ignoreFile = realpath('.') . '/.gitignore'; | ||
| try { | ||
| $ignoreFile = Platform::realpath('.gitignore'); | ||
| } catch (\RuntimeException $exception) { | ||
| $ignoreFile = Platform::getCwd() . '/.gitignore'; | ||
| } | ||
|
|
||
| if (!$this->hasVendorIgnore($ignoreFile)) { | ||
|
|
@@ -269,10 +270,9 @@ protected function interact(InputInterface $input, OutputInterface $output) | |
| '', | ||
| ]); | ||
|
|
||
| $cwd = realpath("."); | ||
|
|
||
| $name = $input->getOption('name'); | ||
| if (null === $name) { | ||
| $cwd = Platform::getCwd(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered by existing tests
|
||
| $name = basename($cwd); | ||
| $name = $this->sanitizePackageNameComponent($name); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |
| use Composer\Semver\Semver; | ||
| use Composer\Spdx\SpdxLicenses; | ||
| use Composer\Util\PackageInfo; | ||
| use Composer\Util\Platform; | ||
| use DateTimeInterface; | ||
| use Symfony\Component\Console\Completion\CompletionInput; | ||
| use Symfony\Component\Console\Formatter\OutputFormatter; | ||
|
|
@@ -359,7 +360,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
| $io->write($package->getName(), false); | ||
| $path = $composer->getInstallationManager()->getInstallPath($package); | ||
| if (is_string($path)) { | ||
| $io->write(' ' . strtok(realpath($path), "\r\n")); | ||
| $io->write(' ' . strtok(Platform::realpath($path), "\r\n")); | ||
| } else { | ||
| $io->write(' null'); | ||
| } | ||
|
|
@@ -581,7 +582,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
| if ($writePath) { | ||
| $path = $composer->getInstallationManager()->getInstallPath($package); | ||
| if (is_string($path)) { | ||
| $packageViewData['path'] = strtok(realpath($path), "\r\n"); | ||
| $packageViewData['path'] = strtok(Platform::realpath($path), "\r\n"); | ||
| } else { | ||
| $packageViewData['path'] = null; | ||
| } | ||
|
|
@@ -903,7 +904,11 @@ protected function printMeta(CompletePackageInterface $package, array $versions, | |
| if ($isInstalledPackage) { | ||
| $path = $this->requireComposer()->getInstallationManager()->getInstallPath($package); | ||
| if (is_string($path)) { | ||
| $io->write('<info>path</info> : ' . realpath($path)); | ||
| try { | ||
| $io->write('<info>path</info> : ' . Platform::realpath($path)); | ||
| } catch (\RuntimeException $exception) { | ||
| $io->write('<info>path</info> : '); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This preserves current behaviour but isn't great IMO.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'd say that is probably ok to expect the realpath to work here and remove the catch. |
||
| } | ||
| } else { | ||
| $io->write('<info>path</info> : null'); | ||
| } | ||
|
|
@@ -1063,13 +1068,12 @@ protected function printPackageInfoAsJson(CompletePackageInterface $package, arr | |
|
|
||
| if (!PlatformRepository::isPlatformPackage($package->getName()) && $installedRepo->hasPackage($package)) { | ||
| $path = $this->requireComposer()->getInstallationManager()->getInstallPath($package); | ||
| $json['path'] = null; | ||
| if (is_string($path)) { | ||
| $path = realpath($path); | ||
| if ($path !== false) { | ||
| $json['path'] = $path; | ||
| try { | ||
| $json['path'] = Platform::realpath($path); | ||
| } catch (\RuntimeException $exception) { | ||
| } | ||
| } else { | ||
| $json['path'] = null; | ||
| } | ||
|
|
||
| if ($package->getReleaseDate() !== null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| use Composer\Json\JsonFile; | ||
| use Composer\CaBundle\CaBundle; | ||
| use Composer\Pcre\Preg; | ||
| use Composer\Util\Platform; | ||
| use Composer\Util\ProcessExecutor; | ||
| use Symfony\Component\Finder\Finder; | ||
| use Symfony\Component\Process\Process; | ||
|
|
@@ -142,8 +143,9 @@ public function compile(string $pharFile = 'composer.phar'): void | |
| __DIR__ . '/../../vendor/symfony/console/Resources/bin/hiddeninput.exe', | ||
| __DIR__ . '/../../vendor/symfony/console/Resources/completion.bash', | ||
| ] as $file) { | ||
| $extraFiles[$file] = realpath($file); | ||
| if (!file_exists($file)) { | ||
| try { | ||
| $extraFiles[$file] = Platform::realpath($file); | ||
| } catch (\RuntimeException $e) { | ||
| throw new \RuntimeException('Extra file listed is missing from the filesystem: '.$file); | ||
|
Comment on lines
145
to
149
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no unit tests on this (large) function. But this reads right to me, better even. $extraFiles[$file] = realpath($file);
if (!file_exists($file)) {
throw new \RuntimeException('Extra file listed is missing from the filesystem: '.$file);
}new: try {
$extraFiles[$file] = Platform::realpath($file);
} catch (\RuntimeException $e) {
throw new \RuntimeException('Extra file listed is missing from the filesystem: '.$file);
}Potentially just: $extraFiles[$file] = Platform::realpath($file);which would also throw a |
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,7 +199,7 @@ public function doRun(InputInterface $input, OutputInterface $output): int | |
| && $input->hasParameterOption('-h', true) === false | ||
| ) { | ||
| $dir = dirname(Platform::getCwd(true)); | ||
| $home = realpath(Platform::getEnv('HOME') ?: Platform::getEnv('USERPROFILE') ?: '/'); | ||
| $home = Platform::realpath(Platform::getEnv('HOME') ?: Platform::getEnv('USERPROFILE') ?: '/'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one too I'd probably try/catch and use |
||
|
|
||
| // abort when we reach the home dir or top of the filesystem | ||
| while (dirname($dir) !== $dir && $dir !== $home) { | ||
|
|
@@ -288,7 +288,7 @@ public function doRun(InputInterface $input, OutputInterface $output): int | |
| } catch (ParsingException $e) { | ||
| $details = $e->getDetails(); | ||
|
|
||
| $file = realpath(Factory::getComposerFile()); | ||
| $file = Platform::realpath(Factory::getComposerFile()); | ||
|
|
||
| $line = null; | ||
| if ($details && isset($details['line'])) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,7 +333,7 @@ public function cleanup(string $type, PackageInterface $package, string $path, ? | |
| } | ||
|
|
||
| foreach ($dirsToCleanUp as $dir) { | ||
| if (is_dir($dir) && $this->filesystem->isDirEmpty($dir) && realpath($dir) !== Platform::getCwd()) { | ||
| if (is_dir($dir) && $this->filesystem->isDirEmpty($dir) && Platform::realpath($dir) !== Platform::getCwd()) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| $this->filesystem->removeDirectoryPhp($dir); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,7 +607,7 @@ protected function normalizePath(string $path): string | |
| return $path; | ||
| } | ||
|
|
||
| $path = rtrim(realpath($basePath) . '/' . implode('/', $removed), '/'); | ||
| $path = rtrim(Platform::realpath($basePath) . '/' . implode('/', $removed), '/'); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| return $path; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform::getCwd()will throw an exception before we get toPlatform::realpath()if there's a problem