merged branch jakzal/FilesystemMirrorCleanup (PR #3844)
Commits
-------
efad5d5
[Filesystem] Prevented infiite loop on windows while calling mirror on symlink. Added test for mirroring symlinks.
Discussion
----------
[Filesystem] Prevented infinite loop on windows while mirrorring symlinks
First check for filetype in *mirror()* method is:
if (is_link($file)) {
$this->symlink($file, $target);
later we see:
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
The later check for links on windows (*$copyOnWindows && is_link($file)*) won't ever get called. Calling *symlink()* in *mirror()* on windows would lead to calling *mirror()* again.
Note that I didn't actually try running it on windows platform. I added a test for mirroring symlinks (non-windows test). I think it'd be good if someone added some windows specific tests to this class.
I also modified the target path:
$target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname());
It didn't use DIRECTORY_SEPARATOR and is equivalent to:
$target = str_replace($originDir, $targetDir, $file->getPathname());
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: ~
Todo: ~
This commit is contained in:
commit
70d49c3c2c
@ -232,12 +232,12 @@ class Filesystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
$target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname());
|
$target = str_replace($originDir, $targetDir, $file->getPathname());
|
||||||
|
|
||||||
if (is_link($file)) {
|
if (is_dir($file)) {
|
||||||
$this->symlink($file, $target);
|
|
||||||
} elseif (is_dir($file)) {
|
|
||||||
$this->mkdir($target);
|
$this->mkdir($target);
|
||||||
|
} elseif (!$copyOnWindows && is_link($file)) {
|
||||||
|
$this->symlink($file, $target);
|
||||||
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
|
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
|
||||||
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
|
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -494,6 +494,25 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFileEquals($file2, $targetPath.'file2');
|
$this->assertFileEquals($file2, $targetPath.'file2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMirrorCopiesLinks()
|
||||||
|
{
|
||||||
|
$this->markAsSkippeIfSymlinkIsMissing();
|
||||||
|
|
||||||
|
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
mkdir($sourcePath);
|
||||||
|
file_put_contents($sourcePath.'file1', 'FILE1');
|
||||||
|
symlink($sourcePath.'file1', $sourcePath.'link1');
|
||||||
|
|
||||||
|
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
|
$this->filesystem->mirror($sourcePath, $targetPath);
|
||||||
|
|
||||||
|
$this->assertTrue(is_dir($targetPath));
|
||||||
|
$this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1');
|
||||||
|
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providePathsForIsAbsolutePath
|
* @dataProvider providePathsForIsAbsolutePath
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user