Skip to content

Commit 5879a54

Browse files
author
Erik Trapman
committed
[FileSystem] verbose error when failing to create symlink in windows due to no administrator-rights
1 parent c07e916 commit 5879a54

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public function rename($origin, $target)
148148
* @param string $originDir The origin directory path
149149
* @param string $targetDir The symbolic link name
150150
* @param Boolean $copyOnWindows Whether to copy files if on Windows
151+
*
152+
* @throws \RuntimeException When creation of symlink raises an error
151153
*/
152154
public function symlink($originDir, $targetDir, $copyOnWindows = false)
153155
{
@@ -169,7 +171,14 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
169171
}
170172

171173
if (!$ok) {
172-
symlink($originDir, $targetDir);
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?");
179+
}
180+
throw $e;
181+
}
173182
}
174183
}
175184

0 commit comments

Comments
 (0)