Index: drush_make.download.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush_make/Attic/drush_make.download.inc,v
retrieving revision 1.1.2.31
diff -u -F '^f' -u -F '^f' -r1.1.2.31 drush_make.download.inc
--- drush_make.download.inc	22 Apr 2010 23:30:14 -0000	1.1.2.31
+++ drush_make.download.inc	25 Apr 2010 18:50:45 -0000
@@ -3,11 +3,9 @@
 
 class DrushMakeDownload {
   var $project;
-  var $path;
 
   function __construct($project) {
     $this->project = $project;
-    $this->path = !empty($this->project->directory_name) ? $this->project->directory_name : $this->project->name;
     $this->preDownload();
   }
 
@@ -33,7 +31,6 @@
 class DrushMakeDownload_CVS extends DrushMakeDownload {
   function download() {
     $name = $this->project->name;
-    $tmp_path = $this->project->tmp_path;
     $download = $this->project->download;
     $command = 'export';
     if (!empty($download['module'])) {
@@ -56,10 +53,13 @@
       }
 
       // Checkout or export the module. CVS can't use absolute paths for named
-      // directories, so change into the tmp directory before checking out. 
-      if (drush_make_cd($tmp_path, "cvs -d%s %s -d%s %s %s", $download['root'], $command, $name, $flags, $download['module'])) {
+      // directories, so change into the directory just above the final
+      // destination for the checkout. 
+      $cd_to_directory = dirname($this->project->download_location);
+      $destination_directory = basename($this->project->download_location);
+      if (drush_make_cd($cd_to_directory, "cvs -d%s %s -d%s %s %s", $download['root'], $command, $destination_directory, $flags, $download['module'])) {
         drush_log(dt('%project @command from %module.', array('%project' => $name, '@command' => $command, '%module' => $download['module'])), 'ok');
-        return $name;
+        return $this->project->download_location;
       }
     }
     else {
@@ -92,16 +92,31 @@
   }
 
   protected function unpack_tar($filename) {
-    // Untar it and then delete the tar file.
+    // Examine the .tar file.
     drush_shell_exec('tar -tf %s', $filename);
+
     $info = drush_shell_exec_output();
     if ($info) {
+      // Determine the first part of the directory in the tarball directory
+      // tree.
       list($first_line) = drush_shell_exec_output();
       list($directory) = explode('/', $first_line);
-      drush_make_cd($this->project->tmp_path, 'tar -xf %s', $filename);
+      // Remove the extra directory from the tarball directory tree if
+      // we've already created it, or if it's the core project. 
+      if ($this->project->name == 'drupal' || $directory == $this->project->project_directory) {
+        $strip_components = 1;
+      }
+      else {
+        $strip_components = 0;
+      }
+      // Untar directly to final resting place -- allows tarballs to be
+      // unpacked directly over an existing structure.
+      drush_shell_exec("tar -x --strip-components %s -C %s -f %s", $strip_components, $this->project->download_location, $filename);
+
+      // Remove the tarball.
       drush_op('unlink', $filename);
 
-      return $directory;
+      return $this->project->download_location;
     }
 
     drush_make_error('PACKAGE_ERROR', dt('Could not retrieve package information for %filename.', array('%filename' => $filename)));
@@ -128,7 +143,8 @@
   }
 
   protected function unpack_zip($filename) {
-    // Find out where contents will end up. Retrieve last column of output using awk.
+    // Find the main directory in the zip file. Retrieve last column of output
+    // using awk.
     drush_shell_exec("unzip -l %s | awk '{print $4;}'", $filename);
     $info = drush_shell_exec_output();
     if ($info) {
@@ -140,15 +156,27 @@
           break;
         }
       }
+
       if (isset($directory)) {
-        drush_shell_exec("unzip %s -d %s", $filename, $this->project->tmp_path);
+        // Remove the extra directory from the destination if it already exists
+        // in the zip file. 
+        if ($directory == $this->project->project_directory) {
+          $download_location = dirname($this->project->download_location);
+        }
+        else {
+          $download_location = $this->project->download_location;
+        }
+
+        // Unzip directly to final resting place -- allows zip files to be
+        // unpacked directly over an existing structure.
+        drush_shell_exec("unzip %s -d %s", $filename, $download_location);
         if (file_exists($filename)) {
           drush_shell_exec('rm %s', $filename);
         }
-        if (is_dir($this->project->tmp_path . '/__MACOSX')) {
-          drush_shell_exec('rm -r %s', $this->project->tmp_path . '/__MACOSX');
+        if (is_dir($download_location . '/__MACOSX')) {
+          drush_shell_exec('rm -r %s', $download_location . '/__MACOSX');
         }
-        return $directory;
+        return $this->project->download_location;
       }
     }
     drush_make_error('PACKAGE_ERROR', dt('Could not retrieve package information for %filename.', array('%filename' => $filename)));
@@ -186,7 +214,6 @@
 class DrushMakeDownload_Git extends DrushMakeDownload {
   function download() {
     $name = $this->project->name;
-    $tmp_path = $this->project->tmp_path;
     $download = $this->project->download;
     if (!empty($download['url'])) {
       // Parse the git repo URL into pieces that we can work with.
@@ -195,10 +222,10 @@
       $alt_url = strpos($download['url'], 'git://') !== FALSE ? "git@{$alt_url[0]}:{$alt_url[1]}" : "git://{$alt_url[0]}/{$alt_url[1]}";
 
       $this->project->download['branch'] = $download['branch'] = isset($download['branch']) ? $download['branch'] : 'master';
-      if (drush_shell_exec("git clone %s %s/%s", $download['url'], $tmp_path, $name)) {
+      if (drush_shell_exec("git clone %s %s", $download['url'], $this->project->download_location)) {
         drush_log(dt('%project cloned from %url.', array('%project' => $name, '%url' => $download['url'])), 'ok');
       }
-      else if (drush_shell_exec("git clone %s %s/%s", $alt_url, $tmp_path, $name)) {
+      else if (drush_shell_exec("git clone %s %s", $alt_url, $this->project->download_location)) {
         drush_log(dt("%project url %orig_url failed, using alternative url %alt_url.", array('%project' => $name, '%orig_url' => $download['url'], '%alt_url' => $alt_url)), 'ok');
         drush_log(dt('%project cloned from %url.', array('%project' => $name, '%url' => $alt_url)), 'ok');
       }
@@ -208,7 +235,7 @@
       // Checkout a branch if one was asked for in the make file
       if ($download['branch'] !== 'master') {
         $cwd = getcwd();
-        chdir($tmp_path . '/' . $name);
+        chdir($this->project->download_location);
         if (drush_shell_exec("git checkout -b %s origin/%s", $download['branch'], $download['branch'])) {
           drush_log(dt("Checked out branch %branch.", array('%branch' => $download['branch'])), 'ok');
         }
@@ -219,7 +246,7 @@
       }
       elseif ($download['revision']) {
         $cwd = getcwd();
-        chdir($tmp_path . '/' . $name);
+        chdir($this->project->download_location);
         if (drush_shell_exec("git checkout %s", $download['revision'])) {
           drush_log(dt("Checked out revision %revision.", array('%revision' => $download['revision'])), 'ok');
         }
@@ -229,10 +256,10 @@
         chdir($cwd);
       }
       // Remove .git/ directory if working-copy flag was not specified.
-      if (!drush_get_option('working-copy') && file_exists($tmp_path . '/' . $name . '/.git')) {
-        drush_shell_exec("rm -rf %s/%s/.git", $tmp_path, $name);
+      if (!drush_get_option('working-copy') && file_exists($this->project->download_location . '/.git')) {
+        drush_shell_exec("rm -rf %s/.git", $this->project->download_location);
       }
-      return $name;
+      return $this->project->download_location;
     }
     else {
       $download['url'] = dt("unspecified location");
@@ -245,17 +272,25 @@
   function download() {
     // @TODO implement revisions, tags
     $name = $this->project->name;
-    $tmp_path = $this->project->tmp_path;
     $download = $this->project->download;
     $command = 'export';
     if (!empty($download['url'])) {
       if (drush_get_option('working-copy')) {
         $command = 'checkout';
       }
-
-      if (drush_shell_exec("bzr %s %s/%s %s", $command, $tmp_path, $name, $download['url'])) {
+      switch ($command) {
+        case 'checkout':
+          // Checkout the project.
+          $result = drush_shell_exec("bzr %s %s %s", $command, $download['url'], $this->project->download_location);
+          break;
+        case 'export':
+          // Export the project.
+          $result = drush_shell_exec("bzr %s %s %s", $command, $this->project->download_location, $download['url']); 
+          break;
+      }
+      if ($result) {
         drush_log(dt('%project branched from %url.', array('%project' => $name, '%url' => $download['url'])), 'ok');
-        return $name;
+        return $this->project->download_location;
       }
     }
     else {
@@ -269,7 +304,6 @@
 class DrushMakeDownload_SVN extends DrushMakeDownload {
   function download() {
     $name = $this->project->name;
-    $tmp_path = $this->project->tmp_path;
     $download = $this->project->download;
     $command = 'export';
     if (!empty($download['url'])) {
@@ -278,14 +312,14 @@
       }
 
       if (!empty($download['username'])) {
-        $result = drush_shell_exec("svn --non-interactive %s %s %s/%s --username %s --password %s", $command, $download['url'], $tmp_path, $name, $download['username'], $download['password']);
+        $result = drush_shell_exec("svn --non-interactive %s %s %s --username %s --password %s", $command, $download['url'], $this->project->download_location, $download['username'], $download['password']);
       }
       else {
-        $result = drush_shell_exec("svn --non-interactive %s %s %s/%s", $command, $download['url'], $tmp_path, $name);
+        $result = drush_shell_exec("svn --non-interactive %s %s %s", $command, $download['url'], $this->project->download_location);
       }
       if ($result) {
         drush_log(dt('%project @command from %url.', array('%project' => $name, '@command' => $command, '%url' => $download['url'])), 'ok');
-        return $this->project->name;
+        return $this->project->download_location;
       }
     }
     else {
@@ -300,15 +334,14 @@
   function download() {
     // @TODO implement revisions, tags
     $name = $this->project->name;
-    $tmp_path = $this->project->tmp_path;
     $download = $this->project->download;
     if (!empty($download['url'])) {
-      if (drush_shell_exec("hg clone %s %s/%s", $download['url'], $tmp_path, $name)) {
+      if (drush_shell_exec("hg clone %s %s", $download['url'], $this->project->download_location)) {
         if (!drush_get_option('working-copy')) {
-          drush_shell_exec('rm -r %s/%s/.hg', $tmp_path, $name);
+          drush_shell_exec('rm -r %s/.hg', $this->project->download_location);
         }
         drush_log(dt('%project cloned from %url.', array('%project' => $name, '%url' => $download['url'])), 'ok');
-        return $name;
+        return $this->project->download_location;
       }
     }
     else {
Index: drush_make.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush_make/Attic/drush_make.drush.inc,v
retrieving revision 1.11.2.40
diff -u -F '^f' -u -F '^f' -r1.11.2.40 drush_make.drush.inc
--- drush_make.drush.inc	25 Feb 2010 05:38:00 -0000	1.11.2.40
+++ drush_make.drush.inc	25 Apr 2010 18:50:46 -0000
@@ -332,7 +332,7 @@ function drush_make_move_build($tmp_path
     }
   }
   else {
-    drush_make_fill_path(dirname($base_path));
+    drush_shell_exec("mkdir -p %s", dirname($base_path));
     drush_shell_exec("mv %s/__build__ %s", $tmp_path, $base_path);
   }
   return TRUE;
Index: drush_make.project.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush_make/Attic/drush_make.project.inc,v
retrieving revision 1.1.2.22
diff -u -F '^f' -u -F '^f' -r1.1.2.22 drush_make.project.inc
--- drush_make.project.inc	22 Apr 2010 23:30:14 -0000	1.1.2.22
+++ drush_make.project.inc	25 Apr 2010 18:50:46 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: drush_make.project.inc,v 1.1.2.22 2010/04/22 23:30:14 dmitrig01 Exp $
+// $Id: drush_make.project.inc,v 1.1.2.21 2010/02/27 16:54:48 yhahn Exp $
 
 /**
  * The base project class.
@@ -24,24 +24,28 @@
    */
   function make() {
     if (empty($this->made)) {
-      $directory = $this->queue->addItem(array($this->downloadClass, 'download'));
-      $full_path = $this->queue->addItem(array($this, 'makePath'), array(), $directory);
-      $move = $this->queue->addItem(array($this, 'move'), array(), array($directory, $full_path));
-      $this->queue->addItem(array($this, 'applyPatches'), array(), array($move));
-      $this->queue->addItem(array($this, 'recurse'), array(), array($move, $directory));
+      $download_location = $this->queue->addItem(array($this, 'findDownloadLocation'));
+      $this->queue->addItem(array($this->downloadClass, 'download'), array(), array($download_location));
+      $this->queue->addItem(array($this, 'applyPatches'), array(), array($download_location));
+      $this->queue->addItem(array($this, 'recurse'), array(), array($download_location));
       $this->made = TRUE;
     }
     return FALSE;
   }
 
-  function makePath($directory) {
+  function findDownloadLocation($directory) {
     $this->path = $this->generatePath();
-    drush_make_fill_path($this->path);
-    if (is_dir($this->path . '/' . $directory)) {
-      drush_set_error(dt('Directory not empty: %directory', array('%directory' => $directory)));
-      drush_shell_exec('rm -r %s', $directory);
+    $this->project_directory = !empty($this->directory_name) ? $this->directory_name : $this->name;
+    $this->download_location = $this->path . '/' . $this->project_directory;
+    // This directory shouldn't exist yet -- if it does, stop.
+    if (is_dir($this->download_location)) {
+      drush_set_error(dt('Directory not empty: %directory', array('%directory' => $this->download_location)));
+      $this->queue->terminate();
     }
-    return $this->path;
+    else {
+      drush_shell_exec("mkdir -p %s", $this->download_location);
+    }
+    return $this->download_location;
   }
 
   /**
@@ -77,25 +81,10 @@
     }
   }
 
-  /**
-   * Move a project to its final resting place.
-   */
-  function move($project_directory) {
-    if (empty($this->directory_name)) {
-      drush_shell_exec("mv %s/%s %s", $this->tmp_path, $project_directory, $this->path);
-    }
-    else {
-      list($project_directory) = array_reverse(explode('/', trim($project_directory, '/')));
-      drush_shell_exec("mv %s/%s %s/%s", $this->tmp_path, $project_directory, $this->path, $this->directory_name);
-      $project_directory = $this->directory_name;
-    }
-    return $this->path . '/' . $project_directory;
-  }
-
-  /**
+   /**
    * Generate the proper path for this project type.
    *
-   * @param $absolute
+   * @param $base
    *   Whether to generate an absolute path, including the temporary directory path.
    *   Defaults to true.
    */
@@ -147,26 +136,17 @@
     $this->install_path = '';
   }
 
-  function makePath($directory) {
-    $this->path = $this->generatePath();
-    drush_make_fill_path(dirname($this->path));
-    if (is_dir($this->path . '/' . $directory)) {
-      drush_set_error(dt('Directory not empty: %directory', array('%directory' => $directory)));
-      drush_shell_exec('rm -r %s', $directory);
-      return FALSE;
+  function findDownloadLocation() {
+    $this->path = $this->download_location = $this->generatePath();
+    $this->project_directory = '';
+    if (is_dir($this->download_location)) {
+      drush_set_error(dt('Directory not empty: %directory', array('%directory' => $this->download_location)));
+      $this->queue->terminate();
     }
-    return $this->path;
-  }
-
-  /**
-   * The core project will always be the base of the build, so it needs to move
-   * itself into place a little differently.
-   *
-   * @TODO ensure that the core project is always created first.
-   */
-  function move($project_directory) {
-    drush_shell_exec("mv %s/%s %s/__build__", $this->tmp_path, $project_directory, $this->tmp_path);
-    return $this->tmp_path . '/__build__';
+    else {
+      drush_shell_exec("mkdir -p %s", $this->download_location);
+    }
+    return $this->download_location;
   }
 }
 
Index: drush_make.utilities.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush_make/Attic/drush_make.utilities.inc,v
retrieving revision 1.1.2.28
diff -u -F '^f' -u -F '^f' -r1.1.2.28 drush_make.utilities.inc
--- drush_make.utilities.inc	22 Apr 2010 23:30:14 -0000	1.1.2.28
+++ drush_make.utilities.inc	25 Apr 2010 18:50:46 -0000
@@ -254,7 +254,7 @@ function drush_make_prepare_install($tmp
 }
 
 function drush_make_tar($tmp_path, $base_path) {
-  drush_make_fill_path(dirname($base_path));
+  drush_shell_exec("mkdir -p %s", dirname($base_path));
   $filename = basename($base_path);
   $dirname = basename($base_path, '.tar.gz');
   // Move the build directory to a more human-friendly name, so that tar will
@@ -270,23 +270,6 @@ function drush_make_tar($tmp_path, $base
 }
 
 /**
- * Wrapper around drush_op('mkdir') to create all the directories up to and including the basename().
- */
-function drush_make_fill_path($path) {
-  $built_path = array();
-  foreach (explode('/', $path) as $part) {
-    if ($part == '.') {
-      continue;
-    }
-    $built_path[] = $part;
-    $current_path = implode('/', $built_path);
-    if ($current_path && !is_dir($current_path)) {
-      drush_op('mkdir', $current_path);
-    }
-  }
-}
-
-/**
  * Logs an error unless the --force-complete command line option is specified.
  */
 function drush_make_error($error_code, $message) {
@@ -391,4 +374,4 @@ function drush_make_get_remote_file($url
   else {
     return drush_set_error('drush_make_download_error', 'Unable to download remote file. No download services supported.');
   }
-}
\ No newline at end of file
+}
