Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2ab3d1e
use `Composer\Util\Platform::realpath()`
BrianHenryIE May 2, 2025
708c809
use `Composer\Util\Platform::realpath()`
BrianHenryIE May 2, 2025
e8a516f
Always treat stream wrappers as absolute paths
BrianHenryIE May 2, 2025
198a7ea
Remove `false` check which no longer can evaluate to false
BrianHenryIE May 2, 2025
9f03eba
Add `::testIsAbsolutePath()`
BrianHenryIE May 2, 2025
ed968c0
Do not treat `file://` paths as absolute path without check it un-pre…
BrianHenryIE May 13, 2025
27fac4b
Recursively call `::realpath()` until `$path` does not change
BrianHenryIE May 13, 2025
d1081a3
Replace `realpath()` with `Platform::realpath()`
BrianHenryIE May 13, 2025
4b5129b
Update src/Composer/Util/Filesystem.php
BrianHenryIE May 13, 2025
21b7a7e
Refactor `::isStreamWrapperPath()` to `public static` method
BrianHenryIE Jun 6, 2025
a23e7ce
Do not treat `file://` as a streamwrapper
BrianHenryIE Jun 6, 2025
40eb099
Return existing path for streamwrapper; throw exception for invalid path
BrianHenryIE Jun 6, 2025
0cd95aa
Move `stream_wrapper_register()` to `bootstrap.php`
BrianHenryIE Jun 6, 2025
598e88e
Replace `realpath()` with `Platform::realpath()`
BrianHenryIE Jun 12, 2025
413dd88
Add test `::realpath()` throws `RuntimeException`
BrianHenryIE Jul 3, 2025
d859488
Add `::testIsStreamWrapperPath()`
BrianHenryIE Jul 3, 2025
7542d71
Add `::testIsLocalPath()`
BrianHenryIE Jul 3, 2025
faeac42
Remove outdated redundant throw
BrianHenryIE Jul 4, 2025
aa70941
Return `false` on `::realpath()` `RuntimeException`
BrianHenryIE Jul 4, 2025
1430918
`continue` on failed `::realpath()`
BrianHenryIE Jul 4, 2025
1baf8bd
Strip `file://` before running system `realpath()`
BrianHenryIE Jul 4, 2025
2c9ed1f
Add `::testRealPathFileStreamStripsScheme()`
BrianHenryIE Jul 4, 2025
d32e015
Update `::isStreamWrapperPath()
BrianHenryIE Jul 4, 2025
463cebe
Don't `file://` prefix stream paths
BrianHenryIE Jul 4, 2025
32e6c08
No need to catch and throw `RuntimeException` here, the message was fine
BrianHenryIE Jul 4, 2025
d359604
Preserve `null` or `realpath()`
BrianHenryIE Jul 4, 2025
6592d1d
Update PhpDoc arguing we how we treat stream wrappers in `::isLocalPa…
BrianHenryIE Jul 4, 2025
95353bc
Preserver behaviour; redundant throw
BrianHenryIE Jul 4, 2025
ea4e18b
Update `::configFromString()` to return pretty `url` in `$repoConfig`
BrianHenryIE Jul 24, 2025
59bdaec
Use `::realpath()` early on `$targetDir` after `::ensureDirectoryExis…
BrianHenryIE Jul 24, 2025
dc204f7
Undo accidental double-prefix of `$targetDir`
BrianHenryIE Jul 24, 2025
6dd3cf8
Add `::testGetPackageTime()` for `realpath()` change
BrianHenryIE Jul 26, 2025
8184e1e
Add `::testCreatesComposerJsonIfNotExists()`
BrianHenryIE Jul 30, 2025
89d71b2
Add `::testClearCacheCommandDirectoryDoesNotExist()`
BrianHenryIE Jul 30, 2025
8bb5b15
Add `::isInstalled()` tests for symlinks
BrianHenryIE Jul 31, 2025
f3ae074
Improve comment explaining `stream_wrapper_register()`
BrianHenryIE Jul 31, 2025
79e9bc5
Check the full `.../composer.json` path
BrianHenryIE Jul 31, 2025
5adaa86
Use `Platform::getCwd()`
BrianHenryIE Aug 1, 2025
f2db2ca
Use `Platform::getCwd()`
BrianHenryIE Aug 1, 2025
9d8b179
Catch more specific `RuntimeException`
BrianHenryIE Aug 1, 2025
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
Next Next commit
use Composer\Util\Platform::realpath()
  • Loading branch information
BrianHenryIE committed May 2, 2025
commit 2ab3d1e26890acee1c2b0ba8335ca7eed308db60
20 changes: 10 additions & 10 deletions src/Composer/Autoload/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Ro
// 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::realpath(Platform::getCwd())));
$vendorPath = $filesystem->normalizePath(Platform::realpath(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);

$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
$vendorPathCode = $filesystem->findShortestPathCode(Platform::realpath($targetDir), $vendorPath, true);
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, Platform::realpath($targetDir), true);

$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
Expand Down Expand Up @@ -493,7 +493,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), '\\', '/'));
Copy link
Author

@BrianHenryIE BrianHenryIE Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file_exists() was just called (previous line) so we can assume that $dir is a valid path, and omit the try/catch

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);
Expand Down Expand Up @@ -1165,10 +1165,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(Platform::realpath($targetDir), $vendorPath, true, true) . " . '/";
$vendorPharPathCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(Platform::realpath($targetDir), $vendorPath, true, true) . " . '/";
$appBaseDirCode = ' => ' . $filesystem->findShortestPathCode(Platform::realpath($targetDir), $basePath, true, true) . " . '/";
$appBaseDirPharCode = ' => \'phar://\' . ' . $filesystem->findShortestPathCode(Platform::realpath($targetDir), $basePath, true, true) . " . '/";

$absoluteVendorPathCode = ' => ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1);
$absoluteVendorPharPathCode = ' => ' . substr(var_export(rtrim('phar://' . $vendorDir, '\\/') . '/', true), 0, -1);
Expand Down Expand Up @@ -1291,7 +1291,7 @@ static function ($matches) use (&$updir): string {
$installPath = strtr(Platform::getCwd(), '\\', '/');
}

$resolvedPath = realpath($installPath . '/' . $updir);
$resolvedPath = Platform::realpath($installPath . '/' . $updir);
Copy link
Member

@Seldaek Seldaek May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a special case where we aren't checking file_exists before, and thus using the false return value as indication that the path doesn't exist and can be skipped.

So I'd probably add a file_exists check before, assuming realpath is changed to throw on failure. Or try/catch to be safer perhaps, because I suppose even if the file exists it might still throw in some weird conditions.

if (false === $resolvedPath) {
continue;
}
Expand Down