Index: drush_pm/drush_pm.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/drush_pm/drush_pm.module,v
retrieving revision 1.18
diff -u -r1.18 drush_pm.module
--- drush_pm/drush_pm.module	22 Mar 2008 02:49:04 -0000	1.18
+++ drush_pm/drush_pm.module	11 Apr 2008 12:17:59 -0000
@@ -124,9 +124,11 @@
   if (DRUSH_URI) {
     $path = conf_path();
     $modulepath = DRUSH_DRUPAL_ROOT .'/'. $path .'/modules/';
+    drush_verbose( t("Trying to use modulepath !modulepath", array( '!modulepath' => $modulepath)));
   }
   
   if (!isset($modulepath) || !file_exists($modulepath)) {
+    drush_verbose( t("Changing modulepath to !modulepath", array( '!modulepath' => $modulepath)));
     $modulepath = DRUSH_DRUPAL_ROOT .'/sites/all/modules/';
   }
 
@@ -154,6 +156,9 @@
         drush_print(t("Project !project successfully installed (version !version).",
           array('!project' => $project_name, '!version' => $release['version'])));
       }
+      else {
+        drush_error( t("Unsuccessfull install of !project by !package_handler", array('!project' => $project_name, '!package_handler'=> $package_handler)));
+      }
     }
     else {
       drush_error(t('Project !project doesn\' exist or has no releases that are compatible with your Drupal version. Skipping.', array('!project' => $project_name)));
@@ -256,6 +261,8 @@
     
     $svn = FALSE;
     $source = DRUSH_DRUPAL_ROOT .'/' . $project['path'];
+    drush_verbose(t('About to update !source', array('!source' => $source)));
+
     if (file_exists($source. '/.svn')) {
       // Skip backup since we need all .svn  directories. Assuming admin can use svn revert if new project is bad.
       drush_verbose(t('Backup skipped because .svn directory was detected. Use Subversion to revert if needed.'));
@@ -264,8 +271,16 @@
     else {
       $date = date('Ymd');
       $backup_dir = DRUSH_DRUPAL_ROOT. "/backup/modules/$date";
-      drush_op('mkdir', $backup_dir, 0777, TRUE);
+      
+      if (!drush_op('mkdir', $backup_dir, 0777, TRUE)) {
+        if ( !file_exists( $backup_dir)) {
+          drush_die(t('Failed to make backup directory !backup_dir', array('!backup_dir' => $backup_dir)));
+        }
+      }
+      
       $backup_target = $backup_dir . '/'. $project['name'];
+      drush_verbose(t('About to rename !source to !backup_target', array('!source' => $source, '!backup_target' => $backup_target)));
+      
       if (!drush_op('rename', $source, $backup_target)) {
         drush_die(t('Failed to backup project directory !source to !backup_target', array('!source' => $source, '!backup_target' => $backup_target)));
       }
@@ -278,6 +293,15 @@
     // move a directory up, so we can copy updated dir to parent
     array_pop($basepath);
     $project_parent_path = DRUSH_DRUPAL_ROOT. '/'. implode('/', $basepath). '/';
+    
+    drush_verbose(t("Calling '!package_handler' with '!project_name', '!project_parent_path'", 
+        array( '!package_handler' => $package_handler,
+          '!project_name' => $project['name'],
+          '!project_parent_path' => $project_parent_path,
+        )
+      )
+    );
+    
     if (!$package_handler($project['name'], $project['releases'][$project['candidate_version']], $project_parent_path)) {
       drush_error(t('Updating project !project failed. Restoring previously installed version.', array('!project' => $project['name'])));
       drush_op('rename', $backup_target, $source);
@@ -434,26 +458,31 @@
  * We need to set the project path by looking at the module location. Ideally, update_status would do this for us.
  */
 function drush_pm_get_project_path($projects) {
+  drush_verbose( 'Getting project path');
+  
   foreach ($projects as $project => $info) {
     if (!isset($info['path'])  && $project != 'drupal') {
       // looks for an enabled module.
       foreach ($info['modules'] as $module => $name) {
         if ($path = drupal_get_path('module', $module)) {
+          drush_verbose( t( "Using path '!path' for '!module'", array( '!path' => $path, '!module' => $module)), 2);
           continue;
         }
       }
+
+      drush_verbose( t("Recalculating path '!path' for '!module'", array( '!path' => $path, '!module' => $module)), 4);
       // As some modules are not located in their project's root directory
       // but in a subdirectory (e.g. all the ecommerce modules), we take the module's
       // info file's path, and then move up until we are at a directory with the
       // project's name.
+
       $parts = explode('/', $path);
-      $i = count($parts) - 1;
-      $stop = array_search($project, $parts);
-      while ($i > $stop) {
-        unset($parts[$i]);
-        $i--;
+      while( $parts[ count($parts)-1] != $project){
+        array_pop( $parts);
       }
+
       $projects[$project]['path'] = implode('/', $parts);
+      drush_verbose( t( "Recalculated path '!path'' for '!module'", array( '!path' => $projects[$project]['path'], '!module' => $module)), 4);
     }
   }
   return $projects;
