Skip to content

Commit

Permalink
Merge branch 'bugfix/drupal-project-109-rename-across-filesystems' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/jpstacey/Robo into jpstacey-bugfix/drupal-project-109-rename-across-filesystems
  • Loading branch information
greg-1-anderson committed Feb 19, 2016
2 parents 1b087b9 + 68f13c4 commit 1b73676
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Task/Archive/Extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public function run()
$filesInExtractLocation = glob("$extractLocation/*");
$hasEncapsulatingFolder = ((count($filesInExtractLocation) == 1) && is_dir($filesInExtractLocation[0]));
if ($hasEncapsulatingFolder && !$this->preserveTopDirectory) {
rename($filesInExtractLocation[0], $this->to);
$this->renameSafely($filesInExtractLocation[0], $this->to);
rmdir($extractLocation);
} else {
rename($extractLocation, $this->to);
$this->renameSafely($extractLocation, $this->to);
}
}
$this->stopTimer();
Expand All @@ -101,6 +101,24 @@ public function run()
return $result;
}

/**
* Rename a file or directory, coping with cross-partition PHP bug.
*
* @see https://bugs.php.net/bug.php?id=54097
*
* @param string $from
* Location to rename from.
* @param string $to
* Location to rename to.
*/
protected function renameSafely($from, $to)
{
if (@rename($from, $to)) {
return;
}
exec("mv " . escapeshellarg($from) . " " . escapeshellarg($to));
}

protected function extractZip($extractLocation)
{
$result = $this->checkExtension('zip extracter', 'zlib');
Expand Down

0 comments on commit 1b73676

Please sign in to comment.