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:
parent
8f995e6c07
commit
59437a4af9
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user