1. $version_control->pre_update() does move the project to backup directory.
2. cvs package_handler looks for CVS in the unexistent project directory.
3. instead of cvs update, cvs checkout is done.

To fix this, pre_update() should copy to backup directory instead of moving. It should do this only under those conditions:
a) package-handler == cvs
b) CVS directory is present in project's dir.

Comments

greg.1.anderson’s picture

This would also fix the problem where php's rename fails for cross-volume moves. Would copying instead of moving cause problems when files are removed from a module? There are existing issues about this, I think. Copy instead of move would at least make it consistent -- drush would need to explicitly remove files that no longer belong in the directory. So, in conclusion, I think the proposed fix is a good idea.

jonhattan’s picture

with package-handler=cvs an update will take care of removing files. If package handler =wget, instead of copy it will move(rename), as now. This is my proposal in #0.

I still haven't think of the way to implement copy,... rsync or drush_shell_exec('cp ..').

Other think to address in a distinct issue is to make wget compatible with vcs'. I've think of scanning the directory in backup and copy each .svn or whatever over the fresh downloaded project. Doing it compatible with any random 3rd library that the module wants placed in its folder is harder.

greg.1.anderson’s picture

I was planning on using rsync, as drush has a nice wrapper function for it. However, moshe thought that rsync wasn't 'core' enough to use in a critical function such as pm-updatecode. Windows support only seems to be getting sketchier in drush over time, though, so maybe this decision could be revisited...? Are we ready to punt Windows-native support for drush, and require at least cygwin on Windows?

jonhattan’s picture

Priority: Normal » Major
jonhattan’s picture

Status: Active » Needs review
StatusFileSize
new3.71 KB

Patch providing drush_copy_dir() and a switch in backup.inc to copy instead of move if package-handler=cvs.

drush_copy_dir() uses cp or rsync although I don't see a reason for cp to fail. There's no copy() for directories in php. The function also overlaps a lot with drush_move_dir().

greg.1.anderson’s picture

StatusFileSize
new4.84 KB

Looks good, but let's be kind to Windows users and do it with a recursive php function. This also improves on #968948: Drush returns an error on dl command on subdomain named subsites.domain.com.

luchochs’s picture

Good!
Some comments:

+++ commands/pm/version_control/backup.inc	2 Dec 2010 18:34:09 -0000
@@ -19,13 +19,21 @@ class drush_pm_version_control_backup im
+      // Move or copy to backup target based in package-handler.
+      $ph = drush_get_option('package-handler', 'wget');
+      if ($ph == 'wget') {
+        if (drush_move_dir($project['full_project_path'], $backup_target)) {
+          return TRUE;
+        }
       }
-      return TRUE;  
-    }
-    else {
-      return FALSE;
+      // cvs or git.
+      else {
+        if (drush_copy_dir($project['full_project_path'], $backup_target)) {
+          return TRUE;
+        }
+      }
+      return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('Failed to backup project directory !project to !backup_target', array('!project' => $project['full_project_path'], '!backup_target' => $backup_target)));

- less indentation is possible.
- the error never occurs.

+++ includes/drush.inc	2 Dec 2010 18:34:10 -0000
@@ -578,6 +578,72 @@ function drush_delete_dir($dir) {
+  else {
+    if (copy($src, $dest) !== TRUE) {
+      return FALSE;
+    }
+  }

- less indentation is possible.

luchochs’s picture

Status: Needs review » Needs work

Update: The observation about the error is wrong, clearer patch in a while.

greg.1.anderson’s picture

Status: Needs work » Needs review
StatusFileSize
new4.83 KB

Here is a new patch with less indentation.

The error DRUSH_PM_BACKUP_FAILED actually will occur if drush_move_dir or drush_copy_dir returns FALSE (e.g. permissions error).

luchochs’s picture

Yes, I was wrong about the error. Alternative proposal:

+      // Move or copy to backup target based in package-handler.
+      $ph = drush_get_option('package-handler', 'wget');
+      if ($ph == 'wget') {
+        return drush_move_dir($project['full_project_path'], $backup_target);
       }
-      return TRUE;  
-    }
-    else {
-      return FALSE;
+      // cvs or git.
+      elseif ($ph == 'cvs' || $ph == 'git_drupalorg') {
+        return drush_copy_dir($project['full_project_path'], $backup_target);
+      }
+      return drush_set_error('DRUSH_PM_BACKUP_FAILED', dt('Failed to backup project directory !project to !backup_target', array('!project' => $project['full_project_path'], '!backup_
     }
luchochs’s picture

Status: Needs review » Reviewed & tested by the community

Rudimentary tests OK for #9 and #10. You choose.

greg.1.anderson’s picture

#10 removes too much indentation and fails to return the correct error code should drush_move_dir or drush_copy_dir fail.

I recommend #9, but will let jonhattan confirm and commit.

jonhattan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks Greg for writing up the recursive copy: I was naturally lazy to do it. With that we have better support for windows. Commited #9 with an actualization to docstrings.

Status: Fixed » Closed (fixed)

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