It would be useful to have an option for pm-update/pm-updatecode to remove the existing module/theme files before extracting the new ones.

  • Many modules go through file name changes and can leave stray files lying around that can either just a) confuse the site maintainer or, worse yet, lead to bugs in the site.
  • On the flip side, sometimes dependencies are copied within the module's directory structure and would cause the module to break were they to suddenly disappear, e.g. jQuery_UI.
  • Lastly, because many revision management systems leave system files within the directory structure, care has to be made to not accidentally delete the wrong files.

So what I propose is an option, --remove-files, that would remove all files within the directory with the exclusion of common known files, e.g. (pseudocode):

$count = 1;
while (system("rm -f {modulepath}" . str_repeat('/*', $count))) {
  $count++;
}

The above code works because the '-f' flag to the UNIX 'rm' command forces files to be deleted but does not descent into directories, and because using the '*' file selector ignores files which start with a period, e.g. ".svn", ".git", etc. It does open a problem with CVS as those directories would have their files removed, so obviously the code would probably work better in PHP with some proper filtering of the directory tree prior to file deletion.

Icing on the cake would be another option named --dont-remove which accepted a list of filenames/paths which were not removed, e.g. to account for unusual revision management tool system files.

Comments

ChrisRut’s picture

:subscribe:

deverman’s picture

Yes this is needed to safely upgrade. Subscribe.

Chris Charlton’s picture

From what I can tell it seems Drush has always moved out the entire folder before exchanging it with the new set. Maybe on SVN/CVS update it may not be the case.

deverman’s picture

Normally we issue an svn delete then a commit and then download the module then svn add and then svn commit.

DamienMcKenna’s picture

@deverman: if you svn-delete the files first you're needlessly complicating the ability to see which files have changed from version to version.

deverman’s picture

ok well...how do you recommend ensuring that there are not straggling files there from old modules that can muck up things?

Chris Charlton’s picture

An CVS/SVN update would (and should) be removing the files for you.

deverman’s picture

Component: Code » PM (dl, en, up ...)

I am confused in comment #7 the whole point of this issue is that this doesn't work properly when using the drush commands.

kirie’s picture

+1 subscribe

jonhattan’s picture

Status: Active » Fixed

updatecode move projects to backup directory and download in /tmp since #826720: "--drupal-project-rename" doesn't seem to work. Same for dl.
To close the cicle, some work is still needed in #940688: updatecode: --version-control=backup stop updatecode --package-handler=cvs to use cvs update and force always a checkout..

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

webservant316’s picture

Version: » 7.x-5.8
Status: Closed (fixed) » Active

if the --no-backup option is used then drush does not remove the existing files. seems like it should in that case as well.

greg.1.anderson’s picture

Version: 7.x-5.8 » 8.x-6.x-dev
Status: Active » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.