Skip to content

Commit b58a806

Browse files
committed
fix mirroring directory into parent directory
1 parent a25c2af commit b58a806

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,15 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
569569
}
570570

571571
$this->mkdir($targetDir);
572-
$targetDirInfo = new \SplFileInfo($targetDir);
572+
$filesCreatedWhileMirroring = [];
573573

574574
foreach ($iterator as $file) {
575-
if ($file->getPathname() === $targetDir || $file->getRealPath() === $targetDir || 0 === strpos($file->getRealPath(), $targetDirInfo->getRealPath())) {
575+
if ($file->getPathname() === $targetDir || $file->getRealPath() === $targetDir || isset($filesCreatedWhileMirroring[$file->getRealPath()])) {
576576
continue;
577577
}
578578

579579
$target = $targetDir.substr($file->getPathname(), $originDirLen);
580+
$filesCreatedWhileMirroring[$target] = true;
580581

581582
if (!$copyOnWindows && is_link($file)) {
582583
$this->symlink($file->getLinkTarget(), $target);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,22 @@ public function testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory()
13621362
$this->assertFalse($this->filesystem->exists($targetPath.'target'));
13631363
}
13641364

1365+
public function testMirrorFromSubdirectoryInToParentDirectory()
1366+
{
1367+
$targetPath = $this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR;
1368+
$sourcePath = $targetPath.'bar'.\DIRECTORY_SEPARATOR;
1369+
$file1 = $sourcePath.'file1';
1370+
$file2 = $sourcePath.'file2';
1371+
1372+
$this->filesystem->mkdir($sourcePath);
1373+
file_put_contents($file1, 'FILE1');
1374+
file_put_contents($file2, 'FILE2');
1375+
1376+
$this->filesystem->mirror($sourcePath, $targetPath);
1377+
1378+
$this->assertFileEquals($file1, $targetPath.'file1');
1379+
}
1380+
13651381
/**
13661382
* @dataProvider providePathsForIsAbsolutePath
13671383
*/

0 commit comments

Comments
 (0)