Merge pull request #2440 from nextcloud/stable10-optimize-createParentDirectories

[stable10] Prevent endless loop in \OC\Files\View::createParentDirect…
This commit is contained in:
Lukas Reschke 2016-12-01 19:02:31 +01:00 committed by GitHub
commit d012965053
1 changed files with 10 additions and 5 deletions

View File

@ -2120,14 +2120,19 @@ class View {
* @return bool * @return bool
*/ */
private function createParentDirectories($filePath) { private function createParentDirectories($filePath) {
$parentDirectory = dirname($filePath); $directoryParts = explode('/', $filePath);
while(!$this->file_exists($parentDirectory)) { $directoryParts = array_filter($directoryParts);
$result = $this->createParentDirectories($parentDirectory); foreach($directoryParts as $key => $part) {
if($result === false) { $currentPathElements = array_slice($directoryParts, 0, $key);
$currentPath = '/' . implode('/', $currentPathElements);
if($this->is_file($currentPath)) {
return false; return false;
} }
if(!$this->file_exists($currentPath)) {
$this->mkdir($currentPath);
}
} }
$this->mkdir($filePath);
return true; return true;
} }
} }