8000 [FileSystem] verbose error when failing to create symlink in windows due to no administrator-rights by ErikTrapman · Pull Request #4577 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FileSystem] verbose error when failing to create symlink in windows due to no administrator-rights #4577

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

Closed
Changes from 1 commit
Commits
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
[FileSystem] verbose error when failing to create symlink in windows …
…due to no administrator-rights
  • Loading branch information
Erik Trapman committed Jun 14, 2012
commit 5879a543b896e251e0a62a5e36e7045d2a3cd588
11 changes: 10 additions & 1 deletion src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public function rename($origin, $target)
* @param string $originDir The origin directory path
* @param string $targetDir The symbolic link name
* @param Boolean $copyOnWindows Whether to copy files if on Windows
*
* @throws \RuntimeException When creation of symlink raises an error
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false)
{
Expand All @@ -169,7 +171,14 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
}

if (!$ok) {
symlink($originDir, $targetDir);
try {
symlink($originDir, $targetDir);
} catch (\ErrorException $e) {
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong as it relies on the fact an error handler is registered (and turns errors into exceptions), which should not be considered as a requirement

Copy link
Author

Choose a reason for hiding this comment

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

True. I could change it by adding an @ to the symlink-statement and reading error_get_last on a false result and then throw an exception with the appr. message.
And how do you see the overall value of this addition?

Copy link
Member

Choose a reason for hiding this comment

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

Better error messages for the end user are always a good idea. But changing the way you implement it would be better indeed

Copy link
Author

Choose a reason for hiding this comment

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

Ok, thnx, i'll come up with another implementation later.

if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($e->getMessage(), 'error code(1314)')) {
throw new \RuntimeException("Unable to create symlink due to error code 1314: A required privilege is not held by the client. Do you have the required Administrator-rights?");
}
throw $e;
}
}
}

Expand Down
0