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

Skip to content

Commit d0d848f

Browse files
author
Erik Trapman
committed
[FileSystem] throwing runtimexception when creation of symlink fails due to an error
1 parent 5879a54 commit d0d848f

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function rename($origin, $target)
149149
* @param string $targetDir The symbolic link name
150150
* @param Boolean $copyOnWindows Whether to copy files if on Windows
151151
*
152-
* @throws \RuntimeException When creation of symlink raises an error
152+
* @throws \RuntimeException When creation of symlink raises an error that should not be suppressed
153153
*/
154154
public function symlink($originDir, $targetDir, $copyOnWindows = false)
155155
{
@@ -171,13 +171,14 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
171171
}
172172

173173
if (!$ok) {
174-
try {
175-
symlink($originDir, $targetDir);
176-
} catch (\ErrorException $e) {
177-
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($e->getMessage(), 'error code(1314)')) {
178-
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?");
174+
if (false === @symlink($originDir, $targetDir)) {
175+
$report = error_get_last();
176+
if (is_array($report) && $report['type'] & error_reporting()) {
177+
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) {
178+
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?');
179+
}
180+
throw new \RuntimeException(sprintf("%s in %s line %s", $report['message'], $report['file'], $report['line']));
179181
}
180-
throw $e;
181182
}
182183
}
183184
}

0 commit comments

Comments
 (0)