1
0
Fork 0

[DownloadFile] Renamed wrapper directory after extract

This fixes error when the extracted directory (from an archive) contains
a folder with the same name. Example:

    $ mv test/test test
    mv: test/test and test/test are identical
pull/303/head
MattKetmo 2012-02-16 17:26:42 +01:00
parent 13183753e6
commit 7d5ba2d756
1 changed files with 7 additions and 0 deletions

View File

@ -111,6 +111,13 @@ abstract class FileDownloader implements DownloaderInterface
$contentDir = glob($path . '/*'); $contentDir = glob($path . '/*');
if (1 === count($contentDir)) { if (1 === count($contentDir)) {
$contentDir = $contentDir[0]; $contentDir = $contentDir[0];
// Rename the content directory to avoid error when moving up
// a child folder with the same name
$temporaryName = md5(time().rand());
rename($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)); rename($file, $path . '/' . basename($file));