Skip to content

Commit

Permalink
bug symfony#12436 [Filesystem] Fixed case for empty folder (yosmanyga)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

[Filesystem] Fixed case for empty folder

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The mirror function should work with an empty folder as source. It should create an empty folder on target path.

Commits
-------

5321741 Fixed case for empty folder
  • Loading branch information
fabpot committed Nov 9, 2014
2 parents 08bebab + 5321741 commit 1f55706
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
}

if ($this->exists($originDir)) {
$this->mkdir($targetDir);
}

foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());

Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,21 @@ public function testMirrorCopiesFilesAndDirectoriesRecursively()
$this->assertFalse($this->filesystem->exists($targetPath.'directory'.DIRECTORY_SEPARATOR.'file1'));
}

public function testMirrorCreatesEmptyDirectory()
{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;

mkdir($sourcePath);

$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;

$this->filesystem->mirror($sourcePath, $targetPath);

$this->assertTrue(is_dir($targetPath));

$this->filesystem->remove($sourcePath);
}

public function testMirrorCopiesLinks()
{
$this->markAsSkippedIfSymlinkIsMissing();
Expand Down

0 comments on commit 1f55706

Please sign in to comment.