Skip to content

Commit

Permalink
Filesystem Component mirror symlinked directory fix
Browse files Browse the repository at this point in the history
  • Loading branch information
malaney authored and fabpot committed Nov 20, 2012
1 parent 0a8c0ee commit f211b19
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
Original file line number Diff line number Diff line change
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->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
Original file line number Diff line number Diff line change
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 f211b19

Please sign in to comment.