fix mirroring directory into parent directory

This commit is contained in:
Christian Flothmann 2019-06-23 10:51:25 +02:00
parent a25c2af559
commit b58a806340
2 changed files with 19 additions and 2 deletions

View File

@ -569,14 +569,15 @@ class Filesystem
}
$this->mkdir($targetDir);
$targetDirInfo = new \SplFileInfo($targetDir);
$filesCreatedWhileMirroring = [];
foreach ($iterator as $file) {
if ($file->getPathname() === $targetDir || $file->getRealPath() === $targetDir || 0 === strpos($file->getRealPath(), $targetDirInfo->getRealPath())) {
if ($file->getPathname() === $targetDir || $file->getRealPath() === $targetDir || isset($filesCreatedWhileMirroring[$file->getRealPath()])) {
continue;
}
$target = $targetDir.substr($file->getPathname(), $originDirLen);
$filesCreatedWhileMirroring[$target] = true;
if (!$copyOnWindows && is_link($file)) {
$this->symlink($file->getLinkTarget(), $target);

View File

@ -1362,6 +1362,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFalse($this->filesystem->exists($targetPath.'target'));
}
public function testMirrorFromSubdirectoryInToParentDirectory()
{
$targetPath = $this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR;
$sourcePath = $targetPath.'bar'.\DIRECTORY_SEPARATOR;
$file1 = $sourcePath.'file1';
$file2 = $sourcePath.'file2';
$this->filesystem->mkdir($sourcePath);
file_put_contents($file1, 'FILE1');
file_put_contents($file2, 'FILE2');
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertFileEquals($file1, $targetPath.'file1');
}
/**
* @dataProvider providePathsForIsAbsolutePath
*/