Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee97214

Browse files
committed
[Filesystem] renameFilesystem::mirror() optioncopy_on_windows tofollow_symlinks
1 parent136bde3 commitee97214

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

‎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+
7.3
5+
---
6+
7+
* Deprecate calling`Filesystem::mirror()` with option`copy_on_windows`, use option`follow_symlinks` instead.
8+
49
7.1
510
---
611

‎src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,18 @@ public function makePathRelative(string $endPath, string $startPath): string
514514
* @param array $options An array of boolean options
515515
* Valid options are:
516516
* - $options['override'] If true, target files newer than origin files are overwritten (see copy(), defaults to false)
517-
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink(), defaults to false)
517+
* - $options['copy_on_windows'] (deprecated) Whether to copy files instead of links on Windows (see symlink(), defaults to false)
518+
* - $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)
518519
* - $options['delete'] Whether to delete files that are not in the source directory (defaults to false)
519520
*
520521
* @throws IOException When file type is unknown
521522
*/
522523
publicfunctionmirror(string$originDir,string$targetDir, ?\Traversable$iterator =null,array$options = []):void
523524
{
525+
if (isset($options['copy_on_windows'])) {
526+
trigger_deprecation('symfony/filesystem','7.3','Calling "%s()" with option "copy_on_windows" is deprecated, use "follow_symlinks" option instead.',__METHOD__);
527+
}
528+
524529
$targetDir =rtrim($targetDir,'/\\');
525530
$originDir =rtrim($originDir,'/\\');
526531
$originDirLen =\strlen($originDir);
@@ -545,10 +550,10 @@ public function mirror(string $originDir, string $targetDir, ?\Traversable $iter
545550
}
546551
}
547552

548-
$copyOnWindows =$options['copy_on_windows'] ??false;
553+
$followSymlinks =$options['follow_symlinks'] ??$options['copy_on_windows'] ??false;
549554

550555
if (null ===$iterator) {
551-
$flags =$copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
556+
$flags =$followSymlinks ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
552557
$iterator =new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir,$flags), \RecursiveIteratorIterator::SELF_FIRST);
553558
}
554559

@@ -563,7 +568,7 @@ public function mirror(string $originDir, string $targetDir, ?\Traversable $iter
563568
$target =$targetDir.substr($file->getPathname(),$originDirLen);
564569
$filesCreatedWhileMirroring[$target] =true;
565570

566-
if (!$copyOnWindows &&is_link($file)) {
571+
if (!$followSymlinks &&is_link($file)) {
567572
$this->symlink($file->getLinkTarget(),$target);
568573
}elseif (is_dir($file)) {
569574
$this->mkdir($target);

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

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

1295+
publicfunctiontestMirrorCopiesLinksByFollowingSymlinks()
1296+
{
1297+
$this->markAsSkippedIfSymlinkIsMissing();
1298+
1299+
$sourcePath =$this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR;
1300+
1301+
mkdir($sourcePath);
1302+
file_put_contents($sourcePath.'file1','FILE1');
1303+
symlink($sourcePath.'file1',$sourcePath.'link1');
1304+
1305+
$targetPath =$this->workspace.\DIRECTORY_SEPARATOR.'target'.\DIRECTORY_SEPARATOR;
1306+
1307+
$this->filesystem->mirror($sourcePath,$targetPath,null, ['follow_symlinks' =>true]);
1308+
1309+
$this->assertDirectoryExists($targetPath);
1310+
$this->assertFalse(is_link($targetPath.\DIRECTORY_SEPARATOR.'link1'));
1311+
}
1312+
12951313
publicfunctiontestMirrorCopiesLinkedDirectoryContents()
12961314
{
12971315
$this->markAsSkippedIfSymlinkIsMissing(true);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp