mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
Merge pull request #51920 from nextcloud/newfolder-race-improvements
fix: improve handling of newFolder race condition handling
This commit is contained in:
commit
2f1c74d43f
1 changed files with 15 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue