composer-patches icon indicating copy to clipboard operation
composer-patches copied to clipboard

Patched projects will be deleted and re-downloaded and patched

Open westende opened this issue 8 years ago • 32 comments

This causes issues when drupal/drupal (version 7) is patched as everything resides in whatever location Drupal has been installed in.

As far as I know it is not possible to run Drupal itself as a dependency, so we would need something like https://github.com/winmillwill/drupal-tangler to resolve this issue. Do you have any other working solutions to this issue?

westende avatar Apr 20 '16 22:04 westende

Isn't something like derhasi/composer-preserve-paths designed to prevent such deletions ? Hint: tested it but, doesn't work in my case (drupal7 too), maybe composer-patches needs to integrate with it.

{
  "name": "madeinlune/drupal7-sandbox",
  "description": "Drupal 7 Composer Sandbox",
  "repositories": [{
    "type": "composer",
    "url": "https://packagist.drupal-composer.org"
  }],
  "require": {
    "composer/installers": "~1.0",
    "cweagans/composer-patches": "1.4.0",
    "derhasi/composer-preserve-paths": "0.1.*",
    "drupal/drupal": "7.43.0",
    "drupal/admin_menu": "7.3.0-rc5"
  },
  "conflict": {
    "drupal/core": "8.*"
  },
  "scripts": {
    "post-create-project-cmd": [
      "rm README.md LICENSE .travis.yml phpunit.xml.dist"
    ]
  },
  "config": {
    "vendor-dir": "vendor"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "extra": {
    "installer-paths": {
      "www/": ["type:drupal-core"],
      "www/sites/all/modules/contrib/{$name}/": ["type:drupal-module"],
      "www/sites/all/themes/contrib/{$name}/": ["type:drupal-theme"],
      "www/sites/all/libraries/{$name}/": ["type:drupal-library"],
      "www/sites/all/drush/{$name}/": ["type:drupal-drush"],
      "www/profiles/{$name}/": ["type:drupal-profile"]
    },
    "patches": {
      "drupal/drupal": {
        "#728702": "https://drupal.org/files/issues/install-redirect-on-empty-database-728702-36.patch",
        "#1470656": "https://drupal.org/files/drupal-1470656-14.patch",
        "#865536": "https://drupal.org/files/drupal-865536-204.patch",
        "#1772316": "https://drupal.org/files/drupal-7.x-allow_profile_change_sys_req-1772316-21.patch",
        "#1275902": "https://drupal.org/files/1275902-15-entity_uri_callback-D7.patch",
        "#1162752": "https://drupal.org/files/drupal-add_taxonomy_filter_to_content_admin-1162752-14.patch"
      }
    },
    "preserve-paths": [
      "www/sites/all/modules",
      "www/sites/all/themes",
      "www/sites/all/libraries",
      "www/sites/all/drush",
      "www/sites/default"
    ]
  }
}

morvans avatar Apr 21 '16 16:04 morvans

Hm, composer-preserve-paths should take care of this, but evidently, it's not. I'll take a look.

cweagans avatar Apr 21 '16 20:04 cweagans

I'm also encountering this issue, downgrading to 1.3.0 of composer-patches doesn't help, neither does explicitly declaring the core root path under preserve-paths.

grahl avatar Apr 25 '16 16:04 grahl

Was this ever working (in any version of this plugin)? It's possible that it had never worked.

cweagans avatar Apr 25 '16 16:04 cweagans

I don't know for sure. I encountered this behavior recently when I tried to use the plugin on a D7 project for the first time. I was only using it on D8 previously. It may have never work with a dependency on D7.

Le 25 avril 2016 18:45:16 CEST, Cameron Eagans [email protected] a écrit :

Was this ever working (in any version of this plugin)? It's possible that it had never worked.


You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/cweagans/composer-patches/issues/42#issuecomment-214436527

Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.

morvans avatar Apr 25 '16 17:04 morvans

It seems none of the events composer-preserve-paths is subscribed to trigger when composer-patches does $installationManager->uninstall on the patched package. Even though one could expect that ScriptEvents::PRE_PACKAGE_UNINSTALL would take care of this.

I have seen some deprecation notices in Composer/Composer regarding these events. Wonder if that has anything to do with it. https://github.com/composer/composer/blob/e2056499cb9641df98c7b1c37279a6085394808a/src/Composer/Script/ScriptEvents.php#L182

I will follow up next weekend.

westende avatar Apr 25 '16 20:04 westende

Here is the link to issue - derhasi/composer-preserve-paths#10

shahinam avatar Apr 29 '16 04:04 shahinam

I think this use-case was never anticipated. Shouldn't the event dispatcher be called before $installationManager->uninstall($localRepository, $uninstallOperation);?

My hypothesis is composer-preserve-paths will back everything up when PRE_PACKAGE_UNINSTALL fires before the uninstall operation in this plugin. Then when the package is installed again, it will be patched because of the implicit trigger of POST_PACKAGE_INSTALL. Also composer-preserve-paths will restore the configured preserved paths.

Does anyone have any usefull feedback on this before diving into the IDE?

westende avatar May 10 '16 19:05 westende

Just clicking through some of the Composer files on Github -- I didn't see anywhere that PRE_PACKAGE_UNINSTALL would have been dispatched. It's entirely possible that simply dispatching that event before $installationManager->uninstall() could do the trick.

cweagans avatar May 10 '16 19:05 cweagans

(And for the record, I was aware of composer-preserve-paths -- I just figured that calling $installationManager->uninstall() would have triggered the event. I don't actually use composer-preserve-paths, though, and therefore didn't test that it played nicely with composer-patches. Happy to maintain that support if you open a PR for it)

cweagans avatar May 10 '16 19:05 cweagans

I understand. Would make sense from a semantic standpoint that $installationManager->uninstall() would fire events implicitly. No harm intended in my feedback. ;-)

I use composer-preserve-paths for Drupal 7 as 3rd party packages are stored inside the root package. I don't like this, but it seems necessary if you don't want to symlink your packages into the root package.

I am going to look into this and create a PR if I can get it to work. This would not only benifit composer-preserve-paths, but all composer plugins which hook in to the event bus. I did see the event dispatcher needs a lot of arguments, so no quick fix today.

westende avatar May 10 '16 20:05 westende

This might be a duplicate of #26 and I've submitted a PR there as well.

jurgenhaas avatar Jul 22 '16 07:07 jurgenhaas

@piepkrak Have you made any progress with this? Looking into the problem, I basically came to the same conclusion (it's funny how an issues can look like total gibberish until you've actually done some of the troubleshooting yourself, after which it makes perfect sense :)). I was not quite sure how to fill the various inputs the event dispatcher needs to dispatch a package event, though.

eelkeblok avatar Oct 25 '16 07:10 eelkeblok

Unfortunately not. Dispatching the event was also the blocker for me at the time. Will try to free up some time next week.

westende avatar Oct 25 '16 08:10 westende

Related question composer/composer#6261

SebCorbin avatar Mar 14 '17 16:03 SebCorbin

PRE_PACKAGE_UNINSTALL is dispatched at https://github.com/composer/composer/blob/122e422682d961233cc5db8b2102cd98b049d4f9/src/Composer/Installer.php#L572

I tried dispatching the event but it is very ugly, but usable, see https://github.com/SebCorbin/composer-patches/commit/1cb9bacba51f8bba0c5f3f322c3bb61e4ceae974

SebCorbin avatar Mar 22 '17 11:03 SebCorbin

Is there something that we can do in this plugin (other than manually dispatching the event) that would cause that line to be run? I haven't stepped through this too much, as this has been fairly low priority for me.

cweagans avatar Mar 22 '17 17:03 cweagans

For the moment, no: either we ask the composer team to dispatch the event on uninstall() (but that would mean on each installation managers or we stick to dispatching the event ourselves.

SebCorbin avatar Mar 22 '17 17:03 SebCorbin

Why not add a PR from https://github.com/SebCorbin/composer-patches/commit/1cb9bacba51f8bba0c5f3f322c3bb61e4ceae974 for the time being. We still face this with Drupal 7 projects on core patched and upgrade/downgrades of core.

clemens-tolboom avatar Nov 02 '17 07:11 clemens-tolboom

I've asked @SebCorbin to create a PR of that commit into this project. I think it makes sense to explicitly fire those events in composer-patches, if composer doesn't do that implicitly.

jcnventura avatar Jan 19 '18 10:01 jcnventura

For now, added the fix to the 7.x branch of https://github.com/drupal-composer/drupal-project/tree/7.x

jcnventura avatar Jan 19 '18 11:01 jcnventura

@cweagans It seems that @SebCorbin is not going to create the PR. Would you consider merging https://github.com/SebCorbin/composer-patches/commit/1cb9bacba51f8bba0c5f3f322c3bb61e4ceae974 anyway?

jcnventura avatar Mar 19 '18 17:03 jcnventura

I'm not sure. I don't really want to just blindly merge it because even though it solves the problems with composer-preserve-paths, it might have unintended effects on other plugins that are listening for those events because that change dispatches the events with empty data. I don't know that we can do much of anything else, but I think it's worth some investigation before merging at least. To my knowledge, that investigation has not been done.

cweagans avatar Mar 19 '18 18:03 cweagans

Thoughts on https://github.com/drupal-composer/preserve-paths/issues/10#issuecomment-468614704?

codebymikey avatar Mar 01 '19 10:03 codebymikey

@cweagans Would there be a way to force composer-patches to patch itself in a post-create-project-cmd step?

Or would you be willing to add a pre-2.x patch if we modify the code in this commit to only be active if we set a flag on the composer.json config?

jcnventura avatar Mar 12 '19 11:03 jcnventura

Also note that if composer-exit-on-patch-failure is set true, the code should try to cleanup before exiting by calling the POST_PACKAGE_UNINSTALL event.

That way stuff doesn't get stuck in the preserve-paths limbo at ~/.cache/composer/preserve-paths.

jcnventura avatar Mar 12 '19 12:03 jcnventura

Created PR #257

jcnventura avatar Mar 12 '19 12:03 jcnventura

This seems to be made worse in composer 2. I'm seeing patches fail to apply on the first run. Seemingly the entire web root for Drupal 7 is lost or does not exist before patches apply (or is not actually installed yet...)

I do notice in composer v2 the patches aren't applying in order. They apply all at the end. I am wondering too if this occurs before the installations is done for drupal/core thus no files exist yet. Running composer install a second time seems to work.

driskell avatar Jan 25 '21 13:01 driskell

@jcnventura I applied the latest commit from 9 days ago and the web directory gets deleted if I use composer 2, seems to work ok with composer 1. For some reason with composer 2 it doesn't seem like composer-patches ever gets patched, didn't try to find out why, I'll stick to composer 1 for now

badrange avatar Apr 28 '21 13:04 badrange

Trying to move a D7 site to use Composer 2 results in failure because the preserve-paths options are ignored, resulting in huge amounts of the codebase being deleted, even with the patch. As a newcomer to Composer with D7 this is quite the nasty surprise, so no more Composer on my D7 projects, back to Drush Make it is.

damienmckenna avatar Nov 17 '21 10:11 damienmckenna

Same here. I would recommend not to use Drupal 7 with composer and preserve-paths until the bug is fixed.

jleehr avatar Nov 19 '21 06:11 jleehr

  • D7 converted to Composer
  • PHP 7.1.33
  • Composer version 2.2.13
        "patches": {
            "cweagans/composer-patches": {
                "Call the preserve paths hooks" : "https://github.com/jcnventura/composer-patches/compare/1.x...jcnventura:fix-preserve-paths.diff"
            }
        },
        "preserve-paths": [
            "web/sites"
        ]

And yes, lost the entire web directory.

steinmb avatar Jun 13 '22 10:06 steinmb