8000 bug #13109 [Filesystem] restore ability to create broken symlinks (ni… · saro0h/symfony@0775080 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0775080

Browse files
committed
bug symfony#13109 [Filesystem] restore ability to create broken symlinks (nicolas-grekas)
This PR was merged into the 2.6 branch. Discussion ---------- [Filesystem] restore ability to create broken symlinks | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#12793 | License | MIT | Doc PR | - Commits ------- 3101202 [Filesystem] restore ability to create broken symlinks
2 parents 667c8c7 + 3101202 commit 0775080

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
106106

107107
try {
108108
$filesystem->symlink($relativeOriginDir, $targetDir);
109+
if (!file_exists($targetDir)) {
110+
throw new IOException('Symbolic link is broken');
111+
}
109112
$output->writeln('The assets were installed using symbolic links.');
110113
} catch (IOException $e) {
111114
if (!$input->getOption('relative')) {
@@ -116,6 +119,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
116119
// try again without the relative option
117120
try {
118121
$filesystem->symlink($originDir, $targetDir);
122+
if (!file_exists($targetDir)) {
123+
throw new IOException('Symbolic link is broken');
124+
}
119125
$output->writeln('It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.');
120126
} catch (IOException $e) {
121127
$this->hardCopy($originDir, $targetDir);

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@ public function rename($origin, $target, $overwrite = false)
286286
*/
287287
public function symlink($originDir, $targetDir, $copyOnWindows = false)
288288
{
289-
$onWindows = strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN';
290-
291-
if ($onWindows && $copyOnWindows) {
289+
if (defined('PHP_WINDOWS_VERSION_MAJOR') && $copyOnWindows) {
292290
$this->mirror($originDir, $targetDir);
293291

294292
return;
@@ -315,10 +313,6 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
315313
}
316314
throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
317315
}
318-
319-
if (!file_exists($targetDir)) {
320-
throw new IOException(sprintf('Symbolic link "%s" is created but appears to be broken.', $targetDir), 0, null, $targetDir);
321-
}
322316
}
323317
}
324318

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,14 @@ public function testSymlink()
686686
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
687687
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
688688

689-
touch($file);
690-
689+
// $file does not exists right now: creating "broken" links is a wanted feature
691690
$this->filesystem->symlink($file, $link);
692691

693692
$this->assertTrue(is_link($link));
693+
694+
// Create the linked file AFTER creating the link
695+
touch($file);
696+
694697
$this->assertEquals($file, readlink($link));
695698
}
696699

0 commit comments

Comments
 (0)
0