Skipping iterations in the mirror() method where the iterated file's path name is equal to the target path

Added a new test what is called testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory

Adjustments to comply with the Symfony Code Standards
This commit is contained in:
Fleuv 2019-01-11 22:17:09 +01:00 committed by Anthony MARTIN
parent 8f995e6c07
commit 59437a4af9
2 changed files with 29 additions and 0 deletions

View File

@ -569,6 +569,10 @@ class Filesystem
}
foreach ($iterator as $file) {
if ($file->getPathName() === $targetDir) {
continue;
}
if (false === strpos($file->getPath(), $originDir)) {
throw new IOException(sprintf('Unable to mirror "%s" directory. If the origin directory is relative, try using "realpath" before calling the mirror method.', $originDir), 0, null, $originDir);
}

View File

@ -1372,6 +1372,31 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->mirror($sourcePath, $targetPath, $iterator);
}
public function testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory()
{
$sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
$directory = $sourcePath.'directory'.\DIRECTORY_SEPARATOR;
$file1 = $directory.'file1';
$file2 = $sourcePath.'file2';
mkdir($sourcePath);
mkdir($directory);
file_put_contents($file1, 'FILE1');
file_put_contents($file2, 'FILE2');
$targetPath = $sourcePath.'target'.\DIRECTORY_SEPARATOR;
$this->filesystem->mirror($sourcePath, $targetPath);
$this->assertTrue(is_dir($targetPath));
$this->assertTrue(is_dir($targetPath.'directory'));
$this->assertFileEquals($file1, $targetPath.'directory'.\DIRECTORY_SEPARATOR.'file1');
$this->assertFileEquals($file2, $targetPath.'file2');
$this->assertFileNotExists($targetPath.'target');
}
/**
* @dataProvider providePathsForIsAbsolutePath
*/