Skip to content

Commit ab92e9f

Browse files
noniagriconomieogizanagi
authored andcommitted
Backport: Improve link script with rollback when using symlink
1 parent b98f2af commit ab92e9f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

link

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php';
1818
use Symfony\Component\Filesystem\Filesystem;
1919

2020
/**
21-
* Links dependencies to components to a local clone of the main symfony/symfony GitHub repository.
21+
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
2222
*
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
2525

2626
$copy = false !== $k = array_search('--copy', $argv, true);
2727
$copy && array_splice($argv, $k, 1);
28+
$rollback = false !== $k = array_search('--rollback', $argv, true);
29+
$rollback && array_splice($argv, $k, 1);
2830
$pathToProject = $argv[1] ?? getcwd();
2931

3032
if (!is_dir("$pathToProject/vendor/symfony")) {
31-
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
33+
echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
3234
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
3335
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
36+
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
3437
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;
3538
exit(1);
3639
}
@@ -51,12 +54,19 @@ foreach ($directories as $dir) {
5154

5255
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
5356
$package = 'symfony/'.basename($dir);
54-
if (!$copy && is_link($dir)) {
55-
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
57+
58+
if (!isset($sfPackages[$package])) {
5659
continue;
5760
}
5861

59-
if (!isset($sfPackages[$package])) {
62+
if ($rollback) {
63+
$filesystem->remove($dir);
64+
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
65+
continue;
66+
}
67+
68+
if (!$copy && is_link($dir)) {
69+
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
6070
continue;
6171
}
6272

@@ -76,3 +86,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
7686
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
7787
$filesystem->remove($cacheDir);
7888
}
89+
90+
if ($rollback) {
91+
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
92+
}

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