diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2025-05-13 09:16:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-13 09:16:54 +0200 |
commit | 2f1c74d43f1df892d3b44802944c8f38d719b2d5 (patch) | |
tree | 09462a45e7b2dbd8a0e48c245b3ed61aef6ac9d6 | |
parent | d4b38083d695e32f7f8db491e37b62c020e601ed (diff) | |
parent | 99364adc1c69bd124d332ac6178138fec4c88297 (diff) | |
download | nextcloud-server-2f1c74d43f1df892d3b44802944c8f38d719b2d5.tar.gz nextcloud-server-2f1c74d43f1df892d3b44802944c8f38d719b2d5.zip |
Merge pull request #51920 from nextcloud/newfolder-race-improvements
fix: improve handling of newFolder race condition handling
-rw-r--r-- | lib/private/Files/Node/Folder.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index a894c69649a..16365948031 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -126,8 +126,21 @@ class Folder extends Node implements \OCP\Files\Folder { $fullPath = $this->getFullPath($path); $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]); - if (!$this->view->mkdir($fullPath) && !$this->view->is_dir($fullPath)) { - throw new NotPermittedException('Could not create folder "' . $fullPath . '"'); + if (!$this->view->mkdir($fullPath)) { + // maybe another concurrent process created the folder already + if (!$this->view->is_dir($fullPath)) { + throw new NotPermittedException('Could not create folder "' . $fullPath . '"'); + } else { + // we need to ensure we don't return before the concurrent request has finished updating the cache + $tries = 5; + while (!$this->view->getFileInfo($fullPath)) { + if ($tries < 1) { + throw new NotPermittedException('Could not create folder "' . $fullPath . '", folder exists but unable to get cache entry'); + } + usleep(5 * 1000); + $tries--; + } + } } $parent = dirname($fullPath) === $this->getPath() ? $this : null; $node = new Folder($this->root, $this->view, $fullPath, null, $parent); |