Skip to content

Commit

Permalink
merged branch malaney/FilesystemMirrorSymlinkFix (PR #6073)
Browse files Browse the repository at this point in the history
This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #6073).

Commits
-------

c1c822b Filesystem Component mirror symlinked directory fix

Discussion
----------

Filesystem Component mirror symlinked directory fix

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets:#6070
Todo:
License of the code: MIT
Documentation PR:

Because of the order in which file types (i.e. dir, link, file) are checked in the Filesystem component, symlinked directories get treated as directories instead of symlinks.  As a result symlinked directories are not truly mirrored when performing a php app/console assets:install.  This PR checks that a file is a symlink BEFORE checking that its a directory and properly symlinks as necessary.
  • Loading branch information
fabpot committed Nov 20, 2012
2 parents 0a8c0ee + f211b19 commit b3c3e89
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Symfony/Component/Filesystem/Filesystem.php
Expand Up @@ -357,14 +357,24 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());

if (is_dir($file)) {
$this->mkdir($target);
} elseif (!$copyOnWindows && is_link($file)) {
$this->symlink($file, $target);
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
if ($copyOnWindows) {
if (is_link($file) || is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} else if (is_dir($file)) {

This comment has been minimized.

Copy link
@sstok

sstok Nov 23, 2012

Contributor

This should be elseif (

And some goes for below

$this->mkdir($target);
} else {
throw new IOException(sprintf('Unable to guess "%s" file type.', $file));
}
} else {
throw new IOException(sprintf('Unable to guess "%s" file type.', $file));
if (is_link($file)) {
$this->symlink($file, $target);
} else if (is_dir($file)) {
$this->mkdir($target);
} else if (is_file($file)) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} else {
throw new IOException(sprintf('Unable to guess "%s" file type.', $file));
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -819,6 +819,26 @@ public function testMirrorCopiesLinks()
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
}

public function testMirrorCopiesLinkedDirectoryContents()
{
$this->markAsSkippedIfSymlinkIsMissing();

$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

mkdir($sourcePath . 'nested/', 0777, true);
file_put_contents($sourcePath.'/nested/file1.txt', 'FILE1');
// Note: We symlink directory, not file
symlink($sourcePath.'nested', $sourcePath.'link1');

$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;

$this->filesystem->mirror($sourcePath, $targetPath);

$this->assertTrue(is_dir($targetPath));
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
}

/**
* @dataProvider providePathsForIsAbsolutePath
*/
Expand Down

0 comments on commit b3c3e89

Please sign in to comment.