You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #30116 [Filesystem] Fix mirroring a directory into itself or in his child with realpath checks (Fleuv, XuruDragon)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Filesystem] Fix mirroring a directory into itself or in his child with realpath checks
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | none / PR #29857
| License | MIT
| Doc PR | n/a
This this the continuity of #29857 by @Fleuv
Fix a bug while trying to mirror a directory into itself or in a child
Adding handle real path checks when mirroring.
Commits
-------
8011f49 Handling relative/absolute path
59437a4 Skipping iterations in the mirror() method where the iterated file's path name is equal to the target path
Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+15-22Lines changed: 15 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -541,6 +541,10 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
541
541
$originDir = rtrim($originDir, '/\\');
542
542
$originDirLen = \strlen($originDir);
543
543
544
+
if (!$this->exists($originDir)) {
545
+
thrownewIOException(sprintf('The origin directory specified "%s" was not found.', $originDir), 0, null, $originDir);
546
+
}
547
+
544
548
// Iterate in destination folder to remove obsolete entries
545
549
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
546
550
$deleteIterator = $iterator;
@@ -564,35 +568,24 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
564
568
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
565
569
}
566
570
567
-
if ($this->exists($originDir)) {
568
-
$this->mkdir($targetDir);
569
-
}
571
+
$this->mkdir($targetDir);
572
+
$targetDirInfo = new \SplFileInfo($targetDir);
570
573
571
574
foreach ($iteratoras$file) {
572
-
if (false === strpos($file->getPath(), $originDir)) {
573
-
thrownewIOException(sprintf('Unable to mirror "%s" directory. If the origin directory is relative, try using "realpath" before calling the mirror method.', $originDir), 0, null, $originDir);
0 commit comments