From 2a6b12fb65e5bec969cbf7e9639be15b96e34a6c Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Mon, 23 Jul 2012 17:30:11 +0200 Subject: [PATCH] fixes rename bug (closes #900) --- src/Composer/Downloader/ArchiveDownloader.php | 4 ++-- src/Composer/Util/Filesystem.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/ArchiveDownloader.php b/src/Composer/Downloader/ArchiveDownloader.php index ed113e0d4..5da9350ea 100644 --- a/src/Composer/Downloader/ArchiveDownloader.php +++ b/src/Composer/Downloader/ArchiveDownloader.php @@ -50,12 +50,12 @@ abstract class ArchiveDownloader extends FileDownloader // Rename the content directory to avoid error when moving up // a child folder with the same name $temporaryName = md5(time().rand()); - rename($contentDir, $temporaryName); + $this->filesystem->rename($contentDir, $temporaryName); $contentDir = $temporaryName; foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) { if (trim(basename($file), '.')) { - rename($file, $path . '/' . basename($file)); + $this->filesystem->rename($file, $path . '/' . basename($file)); } } rmdir($contentDir); diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 1b149cfd6..59239671f 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -14,6 +14,7 @@ namespace Composer\Util; /** * @author Jordi Boggiano + * @author Johannes M. Schmitt */ class Filesystem { @@ -53,6 +54,20 @@ class Filesystem } } + public function rename($source, $target) + { + if (defined('PHP_WINDOWS_VERSION_BUILD') || ! function_exists('exec')) { + rename($source, $target); + + return; + } + + exec('mv '.escapeshellarg($source).' '.escapeshellarg($target), $output, $returnCode); + if (0 !== $returnCode) { + throw new \RuntimeException(sprintf('Could not rename "%s" to "%s".', $source, $target)); + } + } + /** * Returns the shortest path from $from to $to *