From abf40ceb404e00593e2f9ac6e9adbb8a1d424d55 Mon Sep 17 00:00:00 2001 From: noniagriconomie Date: Fri, 21 Aug 2020 19:05:22 +0200 Subject: [PATCH] Improve link script with rollback when using symlink --- link | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/link b/link index 1525ab0cb9bbf..639006e2ca43a 100755 --- a/link +++ b/link @@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php'; use Symfony\Component\Filesystem\Filesystem; /** - * Links dependencies to components to a local clone of the main symfony/symfony GitHub repository. + * Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository. * * @author Kévin Dunglas */ $copy = false !== $k = array_search('--copy', $argv, true); $copy && array_splice($argv, $k, 1); +$rollback = false !== $k = array_search('--rollback', $argv, true); +$rollback && array_splice($argv, $k, 1); $pathToProject = $argv[1] ?? getcwd(); if (!is_dir("$pathToProject/vendor/symfony")) { - echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL; + echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL; echo "Usage: $argv[0] /path/to/the/project".PHP_EOL; echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL; + echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL; 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; exit(1); } @@ -44,7 +47,6 @@ $directories = array_merge(...array_values(array_map(function ($part) { }, $braces))); $directories[] = __DIR__.'/src/Symfony/Contracts'; - foreach ($directories as $dir) { if ($filesystem->exists($composer = "$dir/composer.json")) { $sfPackages[json_decode(file_get_contents($composer))->name] = $dir; @@ -53,12 +55,19 @@ foreach ($directories as $dir) { foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $package = 'symfony/'.basename($dir); - if (!$copy && is_link($dir)) { - echo "\"$package\" is already a symlink, skipping.".PHP_EOL; + + if (!isset($sfPackages[$package])) { continue; } - if (!isset($sfPackages[$package])) { + if ($rollback) { + $filesystem->remove($dir); + echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL; + continue; + } + + if (!$copy && is_link($dir)) { + echo "\"$package\" is already a symlink, skipping.".PHP_EOL; continue; } @@ -78,3 +87,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) { $filesystem->remove($cacheDir); } + +if ($rollback) { + echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL; +} 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