Skip to content

Commit 3b42ca9

Browse files
minor #34758 Allow copy instead of symlink for ./link script (ogizanagi)
This PR was merged into the 3.4 branch. Discussion ---------- Allow copy instead of symlink for ./link script | Q | A | ------------- | --- | Branch? | 3.4 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | N/A <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | N/A Not the most efficient way to work, but sometimes it helps to test a bug fix/feature within an existing project for which symlinks can't be resolved due to the dev environment (e.g: a Vagrant where only the current project directory is mounted). Commits ------- b28fe66 Allow copy instead of symlink for ./link script
2 parents 30294c4 + b28fe66 commit 3b42ca9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

link

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ use Symfony\Component\Filesystem\Filesystem;
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
2525

26+
$copy = false !== $k = array_search('--copy', $argv, true);
27+
$copy && array_splice($argv, $k, 1);
2628
$pathToProject = $argv[1] ?? getcwd();
2729

2830
if (!is_dir("$pathToProject/vendor/symfony")) {
29-
echo 'Link dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
30-
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL.PHP_EOL;
31+
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
32+
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
33+
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
3134
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
3235
exit(1);
3336
}
@@ -48,7 +51,7 @@ foreach ($directories as $dir) {
4851

4952
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
5053
$package = 'symfony/'.basename($dir);
51-
if (is_link($dir)) {
54+
if (!$copy && is_link($dir)) {
5255
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
5356
continue;
5457
}
@@ -57,11 +60,17 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
5760
continue;
5861
}
5962

60-
$sfDir = '\\' === DIRECTORY_SEPARATOR ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir)));
63+
$sfDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir)));
6164

6265
$filesystem->remove($dir);
63-
$filesystem->symlink($sfDir, $dir);
64-
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
66+
67+
if ($copy) {
68+
$filesystem->mirror($sfDir, $dir);
69+
echo "\"$package\" has been copied from \"$sfPackages[$package]\".".PHP_EOL;
70+
} else {
71+
$filesystem->symlink($sfDir, $dir);
72+
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
73+
}
6574
}
6675

6776
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {

0 commit comments

Comments
 (0)
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