Skip to content

Commit fdcc518

Browse files
committed
[Filesystem] rename Filesystem::mirror() option copy_on_windows to follow_symlinks
1 parent 9909410 commit fdcc518

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

UPGRADE-6.4.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 6.3 to 6.4
22
=======================
33

4+
Filesystem
5+
----------
6+
7+
* Deprecate calling `Filesystem::mirror()` with option `copy_on_windows`, use option `follow_symlinks` instead.
8+
49
HttpFoundation
510
--------------
611

src/Symfony/Component/Filesystem/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Deprecate calling `Filesystem::mirror()` with option `copy_on_windows`, use option `follow_symlinks` instead.
8+
49
5.4
510
---
611

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ public function makePathRelative(string $endPath, string $startPath): string
523523
* @param array $options An array of boolean options
524524
* Valid options are:
525525
* - $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
526-
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
526+
* - $options['copy_on_windows'] (deprecated) Whether to copy files instead of links on Windows (see symlink(), defaults to false)
527+
* - $options['follow_symlinks'] Whether to copy files instead of links, where using symlinks in not working: windows, different drive, docker context not supporting symlinks (see symlink(), defaults to false)
527528
* - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
528529
*
529530
* @return void
@@ -532,6 +533,9 @@ public function makePathRelative(string $endPath, string $startPath): string
532533
*/
533534
public function mirror(string $originDir, string $targetDir, \Traversable $iterator = null, array $options = [])
534535
{
536+
if (isset($options['copy_on_windows'])) {
537+
trigger_deprecation('symfony/filesystem', '6.4', 'Calling "%s()" with option "copy_on_windows" is deprecated, use "follow_symlinks" option instead.', __METHOD__);
538+
}
535539
$targetDir = rtrim($targetDir, '/\\');
536540
$originDir = rtrim($originDir, '/\\');
537541
$originDirLen = \strlen($originDir);
@@ -556,10 +560,10 @@ public function mirror(string $originDir, string $targetDir, \Traversable $itera
556560
}
557561
}
558562

559-
$copyOnWindows = $options['copy_on_windows'] ?? false;
563+
$followSymlinks = ($options['follow_symlinks'] ?? false) || ($options['copy_on_windows'] ?? false);
560564

561565
if (null === $iterator) {
562-
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
566+
$flags = $followSymlinks ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
563567
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
564568
}
565569

@@ -574,7 +578,7 @@ public function mirror(string $originDir, string $targetDir, \Traversable $itera
574578
$target = $targetDir.substr($file->getPathname(), $originDirLen);
575579
$filesCreatedWhileMirroring[$target] = true;
576580

577-
if (!$copyOnWindows && is_link($file)) {
581+
if (!$followSymlinks && is_link($file)) {
578582
$this->symlink($file->getLinkTarget(), $target);
579583
} elseif (is_dir($file)) {
580584
$this->mkdir($target);

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,24 @@ public function testMirrorCopiesLinks()
12811281
$this->assertTrue(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
12821282
}
12831283

1284+
public function testMirrorCopiesLinksByFollowingSymlinks()
1285+
{
1286+
$this->markAsSkippedIfSymlinkIsMissing();
1287+
1288+
$sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
1289+
1290+
mkdir($sourcePath);
1291+
file_put_contents($sourcePath.'file1', 'FILE1');
1292+
symlink($sourcePath.'file1', $sourcePath.'link1');
1293+
1294+
$targetPath = $this->workspace.\DIRECTORY_SEPARATOR.'target'.\DIRECTORY_SEPARATOR;
1295+
1296+
$this->filesystem->mirror($sourcePath, $targetPath, null, ['follow_symlinks' => true]);
1297+
1298+
$this->assertDirectoryExists($targetPath);
1299+
$this->assertFalse(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
1300+
}
1301+
12841302
public function testMirrorCopiesLinkedDirectoryContents()
12851303
{
12861304
$this->markAsSkippedIfSymlinkIsMissing(true);

0 commit comments

Comments
 (0)