Skip to content
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

Fix error when vendor dir contains broken symlinks #11670

Merged
merged 1 commit into from Oct 6, 2023

Conversation

vtsykun
Copy link
Contributor

@vtsykun vtsykun commented Oct 1, 2023

Fixes #11668

Copy link

@Rodrigostrong Rodrigostrong left a comment

Choose a reason for hiding this comment

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

Eu

@@ -251,6 +251,9 @@ public function ensureDirectoryExists(string $directory)
$directory.' exists and is not a directory.'
);
}
if (is_link($directory)) {
@$this->unlinkImplementation($directory);
Copy link

Choose a reason for hiding this comment

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

When the unlink gives something wrong you never see this, otherwise there is no reason to 'supress' the termination cause the link is always exists (is_link)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, I added an error message when the symbolic link could not be deleted. But at the same time I'd like to make minimal changes to current logic, so I added supress on unlink

@vtsykun vtsykun force-pushed the fix/broken-links branch 2 times, most recently from d04c4e0 to 2c2d0f4 Compare October 2, 2023 10:49
$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'] ?? ''));
Copy link
Contributor

Choose a reason for hiding this comment

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

please use a if/else rather than a ternary here. Currently, your @ suppresses errors for the whole ternary, which is not what we want here as it could hide issues in the composer code.


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

Choose a reason for hiding this comment

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

Why not throwing the RuntimeException here instead of attempting to create the directory but remembering the previous error ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to add a new point where an exception could be thrown, (i.e if unlink == false OR mkdir == false). Unlink made fails on Windows by may reasons, like antivirus, FS locking, so I throw an exception like before only on mkdir = false. But I can change that if it's safe

@Seldaek Seldaek merged commit 3e22e1c into composer:main Oct 6, 2023
20 checks passed
@Seldaek
Copy link
Member

Seldaek commented Oct 6, 2023

Thanks

@Seldaek Seldaek added this to the 2.6 milestone Oct 6, 2023
@Seldaek Seldaek added the Bug label Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error Unhandled promise rejection with DirectoryNotFoundException
5 participants