Skip to content

Commit

Permalink
Fix error when vendor dir contains broken symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Oct 2, 2023
1 parent 64c5bdd commit d04c4e0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Composer/Util/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,15 @@ public function ensureDirectoryExists(string $directory)
$directory.' exists and is not a directory.'
);
}
if (!@mkdir($directory, 0777, true)) {
throw new \RuntimeException(
$directory.' does not exist and could not be created.'
);

$error = null;
if (is_link($directory) && !@$this->unlinkImplementation($directory)) {
$error = 'Could not delete symbolic link '.$directory.': ' . (error_get_last()['message'] ?? '');
}

$error = @mkdir($directory, 0777, true) ? null : ($error ?: $directory.' does not exist and could not be created: ' . (error_get_last()['message'] ?? ''));

Check failure on line 260 in src/Composer/Util/Filesystem.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, false)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.

Check failure on line 260 in src/Composer/Util/Filesystem.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, true)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.
if (null !== $error) {
throw new \RuntimeException($error);
}
}
}
Expand Down

0 comments on commit d04c4e0

Please sign in to comment.