From abbfb468fe8a3b2802db3d1d07d4c2117af77e03 Mon Sep 17 00:00:00 2001 From: Fleuv Date: Fri, 11 Jan 2019 22:17:09 +0100 Subject: [PATCH 1/3] Skipping iterations in the mirror() method where the iterated file's path name is equal to the target path --- src/Symfony/Component/Filesystem/Filesystem.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 2d703843dc36b..1c01373996802 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -569,6 +569,10 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o } 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); } From 8c866387dbed701338baeaf31abfc295396112b1 Mon Sep 17 00:00:00 2001 From: Fleuv Date: Fri, 11 Jan 2019 22:20:08 +0100 Subject: [PATCH 2/3] Added a new test what is called testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory --- .../Filesystem/Tests/FilesystemTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 521c16b710222..42588ee991a38 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1372,6 +1372,31 @@ public function testMirrorWithCustomIteratorWithRelativePath() $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->assertFalse(file_exists($targetPath.'target')); + } + /** * @dataProvider providePathsForIsAbsolutePath */ From 71c4d2244608be67b7d8b0bd5218b22903feffa8 Mon Sep 17 00:00:00 2001 From: Fleuv Date: Fri, 11 Jan 2019 22:33:07 +0100 Subject: [PATCH 3/3] Adjustments to comply with the Symfony Code Standards --- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 42588ee991a38..b308287140ff4 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -1384,7 +1384,7 @@ public function testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory() file_put_contents($file1, 'FILE1'); file_put_contents($file2, 'FILE2'); - $targetPath = $sourcePath . 'target' . \DIRECTORY_SEPARATOR; + $targetPath = $sourcePath.'target'.\DIRECTORY_SEPARATOR; $this->filesystem->mirror($sourcePath, $targetPath); @@ -1394,7 +1394,7 @@ public function testMirrorAvoidCopyingTargetDirectoryIfInSourceDirectory() $this->assertFileEquals($file1, $targetPath.'directory'.\DIRECTORY_SEPARATOR.'file1'); $this->assertFileEquals($file2, $targetPath.'file2'); - $this->assertFalse(file_exists($targetPath.'target')); + $this->assertFileNotExists($targetPath.'target'); } /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy