fixes rename bug (closes #900)
parent
ac29308eb7
commit
2a6b12fb65
|
@ -50,12 +50,12 @@ abstract class ArchiveDownloader extends FileDownloader
|
||||||
// Rename the content directory to avoid error when moving up
|
// Rename the content directory to avoid error when moving up
|
||||||
// a child folder with the same name
|
// a child folder with the same name
|
||||||
$temporaryName = md5(time().rand());
|
$temporaryName = md5(time().rand());
|
||||||
rename($contentDir, $temporaryName);
|
$this->filesystem->rename($contentDir, $temporaryName);
|
||||||
$contentDir = $temporaryName;
|
$contentDir = $temporaryName;
|
||||||
|
|
||||||
foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
|
foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) {
|
||||||
if (trim(basename($file), '.')) {
|
if (trim(basename($file), '.')) {
|
||||||
rename($file, $path . '/' . basename($file));
|
$this->filesystem->rename($file, $path . '/' . basename($file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rmdir($contentDir);
|
rmdir($contentDir);
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Filesystem
|
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
|
* Returns the shortest path from $from to $to
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue