8000 Lock copied files to prevent removing files needed by other recipes by dbrumann · Pull Request #451 · symfony/flex · GitHub
[go: up one dir, main page]

Skip to content

Lock copied files to prevent removing files needed by other recipes #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2019
Merged

Lock copied files to prevent removing files needed by other recipes #451

merged 1 commit into from
Feb 21, 2019

Conversation

dbrumann
Copy link
@dbrumann dbrumann commented Dec 13, 2018

This PR modifies the CopyFromRecipeConfigurator so that it will store a list of copied files in symfony.lock and when a recipe is about to be unconfigured, it will check the list of locked files to prevent removal. This should fix #428

How to reproduce the issue

composer create-project symfony/skeleton example
cd example
composer remove console

This will remove both files installed through the recipe bin/console and config/bootstrap.php. As symfony/framework-bundle relies on the bootstrap-file as well, when trying to access the website, you will get an error due to the missing file.

How to verify the fix

Create a new project based on symfony/skeleton and replace flex inside the example project with a local copy of this branch:

composer create-project symfony/skeleton example
cd example
rm -rf vendor/symfony/flex
ln -s path/to/local/flex vendor/symfony/flex

Since the symfony.lock was created during setup of the project it will not yet keep track of the copied files and needs to be updated first. An easy way to do this, is to remove the current file and run composer fix-recipes to create a new one:

rm symfony.lock
composer fix-recipes

Alternatively removing a recipe and then requiring it again will update the lock as well, but it needs to be done for each recipe, as otherwise the list of locked files would be incomplete.

Now when we remove the console again, opening the page in the browser should still work and the file config/bootstrap.php should still exist as it is locked by the framework-bundle.

BC Breaks

None, as far as I can tell. For newly required recipes the files will be tracked. The new key for files in symfony.lock was not previously used and should not interfere with existing behavior.

Known limitations

Unfortunately if any of the previously installed recipes has conflicting files, this will not be recognized unless the recipe is removed and then installed again.

@nicolas-grekas
8000 Copy link
Member

(rebase needed)

@nicolas-grekas
Copy link
Member

Hi @dbrumann, friendly ping to know the status here :)

@dbrumann
Copy link
Author

Hi @nicolas-grekas. Sorry for not updating. I'm currently busy settling into a new client project.

Writing tests for this was a bit tricky due to the Lock-class requiring a file to write to. I think the rebase and the flexible root-dir made this a bit easier, but I had no time to confirm this. I don't feel comfortable mocking the calls to Lock as I want to ensure the file list is handled properly.

I won't have time until Wednesday next week though. I set the end of the first week of February as my personal deadline for this.

@dbrumann dbrumann changed the title [WIP] Lock copied files to prevent removing files needed by other recipes Lock copied files to prevent removing files needed by other recipes Feb 8, 2019
@dbrumann
Copy link
Author
dbrumann commented Feb 8, 2019

Hey @nicolas-grekas I think this is ready. Let me know if something is missing for you.

Copy link
Author
@dbrumann dbrumann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an issue after my last changes. When manually trying to verify the fix right now, it did not seem to work. I will update as soon as I figure out what went wrong.

The issue is fixed. I messed up when replacing my array_map-construct with array_column.

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, works like a charm!

- Allows passing lock to configurators.
- Stores copied files in lock.
- Ignores locked files on remove.
@nicolas-grekas
Copy link
Member

Thank you @dbrumann.

@nicolas-grekas nicolas-grekas merged commit 896e709 into symfony:master Feb 21, 2019
nicolas-grekas added a commit that referenced this pull request Feb 21, 2019
…recipes (dbrumann)

This PR was merged into the 1.2-dev branch.

Discussion
----------

Lock copied files to prevent removing files needed by other recipes

This PR modifies the `CopyFromRecipeConfigurator` so that it will store a list of copied files in symfony.lock and when a recipe is about to be unconfigured, it will check the list of locked files to prevent removal. This should fix #428

## How to reproduce the issue

```
composer create-project symfony/skeleton example
cd example
composer remove console
```

This will remove both files installed through the recipe `bin/console` and `config/bootstrap.php`. As `symfony/framework-bundle` relies on the bootstrap-file as well, when trying to access the website, you will get an error due to the missing file.

## How to verify the fix

Create a new project based on `symfony/skeleton` and replace flex inside the example project with a local copy of this branch:

```
composer create-project symfony/skeleton example
cd example
rm -rf vendor/symfony/flex
ln -s path/to/local/flex vendor/symfony/flex
```

Since the `symfony.lock` was created during setup of the project it will not yet keep track of the copied files and needs to be updated first. An easy way to do this, is to remove the current file and run `composer fix-recipes` to create a new one:

```
rm symfony.lock
composer fix-recipes
```

Alternatively removing a recipe and then requiring it again will update the lock as well, but it needs to be done for each recipe, as otherwise the list of locked files would be incomplete.

Now when we remove the console again, opening the page in the browser should still work and the file `config/bootstrap.php` should still exist as it is locked by the framework-bundle.

## BC Breaks

None, as far as I can tell. For newly required recipes the files will be tracked. The new key for files in `symfony.lock` was not previously used and should not interfere with existing behavior.

## Known limitations

Unfortunately if any of the previously installed recipes has conflicting files, this will not be recognized unless the recipe is removed and then installed again.

Commits
-------

896e709 Adds file locking for CopyFromRecipe.
tgalopin pushed a commit to tgalopin/flex that referenced this pull request Dec 3, 2020
nicolas-grekas added a commit that referenced this pull request May 28, 2025
…pes (nicolas-grekas)

This PR was merged into the 2.x branch.

Discussion
----------

Don't remove still-referenced files when unconfiguring recipes

Instead of #706
Fixes broken logic added in #451, which didn't account for folders.
The new logic uses only the symfony.lock file and not the recipe anymore to decide which files to remove.

Commits
-------

6443e31 Don't remove still-referenced files when unconfiguring recipes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling of already existing files when requiring/removing a pack
4 participants
0