1
0
Fork 0

Fix ensureDirectoryExists not working when a broken symlink appears somewhere in the path, fixes #11864

pull/11880/head
Jordi Boggiano 2024-03-04 14:39:30 +01:00
parent c42bb68aff
commit 1dc2c93261
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 15 additions and 1 deletions

View File

@ -257,7 +257,21 @@ class Filesystem
} }
if (!@mkdir($directory, 0777, true)) { if (!@mkdir($directory, 0777, true)) {
throw new \RuntimeException($directory.' does not exist and could not be created: '.(error_get_last()['message'] ?? '')); $e = new \RuntimeException($directory.' does not exist and could not be created: '.(error_get_last()['message'] ?? ''));
// in pathological cases with paths like path/to/broken-symlink/../foo is_dir will fail to detect path/to/foo
// but normalizing the ../ away first makes it work so we attempt this just in case, and if it still fails we
// report the initial error we had with the original path, and ignore the normalized path exception
// see https://github.com/composer/composer/issues/11864
$normalized = $this->normalizePath($directory);
if ($normalized !== $directory) {
try {
$this->ensureDirectoryExists($normalized);
return;
} catch (\Throwable $ignoredEx) {}
}
throw $e;
} }
} }
} }