10000 Fix symlinks on Windows. by david-garcia-garcia · Pull Request #21887 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix symlinks on Windows. #21887

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
Prev Previous commit
Refactor symlink fallback.
  • Loading branch information
david-garcia-garcia committed Mar 6, 2017
commit 425120951d97d9ea36089144dfa9eb5ea5f9f47a
36 changes: 18 additions & 18 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,24 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
}

if (!$ok) {
if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
// Creating symlinks on windows through PHP's symlink function
// is totally broken with relative paths.
// @see https://github.com/php/php-src/pull/1243
// @see https://bugs.php.net/bug.php?id=69473
$exitCode = 1;
$output = array();
// Without this cleanup for backslashes symlink will
// be created but completely broken.
$originDir = str_replace('/', DIRECTORY_SEPARATOR, $originDir);
$targetDir = str_replace('/', DIRECTORY_SEPARATOR, $targetDir);
// Careful as parameters here are ordered differently
// compared to PHP's symlink function.
@exec(sprintf('mklink /d %s %s', escapeshellarg($targetDir), escapeshellarg($originDir)), $ouptput, $exitCode);
$ok = $exitCode == 0;
} else {
$ok = @symlink($originDir, $targetDir);
}
$ok = @symlink($originDir, $targetDir);
}

if (!$ok && strncasecmp(PHP_OS, 'WIN', 3) == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor comment: to detect if the OS is macOS, we use the PHP_OS constant as follows: 'Darwin' === PHP_OS But for Windows, we always use this indirect detection: '\\' === DIRECTORY_SEPARATOR

// Creating symlinks on windows through PHP's symlink function
// is totally broken with relative paths.
// @see https://github.com/php/php-src/pull/1243
// @see https://bugs.php.net/bug.php?id=69473
$exitCode = 1;
$output = array();
// Without this cleanup for backslashes symlink will
// be created but completely broken.
$originDir = str_replace('/', DIRECTORY_SEPARATOR, $originDir);
$targetDir = str_replace('/', DIRECTORY_SEPARATOR, $targetDir);
// Careful as parameters here are ordered differently
// compared to PHP's symlink function.
@exec(sprintf('mklink /d %s %s', escapeshellarg($targetDir), escapeshellarg($originDir)), $ouptput, $exitCode);
$ok = $exitCode == 0;
}

if (!$ok) {
Expand Down
0