Skip to content

Commit 4b78f63

Browse files
author
dustinhuynh
committed
Add fallback check for directories created between calls
1 parent 2c52ac4 commit 4b78f63

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

classes/local/store/object_file_system.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,15 @@ public function copy_object_from_external_to_local_by_hash($contenthash, $object
336336

337337
if ($initiallocation === OBJECT_LOCATION_EXTERNAL) {
338338

339-
$localpath = $this->get_local_path_from_hash($contenthash);
340339
$localdirpath = $this->get_fulldir_from_hash($contenthash);
341340

342341
// Folder may not exist yet if pulling a file that came from another environment.
343342
if (!is_dir($localdirpath)) {
344-
if (!mkdir($localdirpath, $this->dirpermissions, true)) {
343+
mkdir($localdirpath, $this->dirpermissions, true);
344+
// Re-check after mkdir() to handle the race where $localdirpath is created between is_dir() and mkdir().
345+
if (!is_dir($localdirpath)) {
345346
// Permission trouble.
346-
throw new file_exception('storedfilecannotcreatefiledirs');
347+
throw new \file_exception('storedfilecannotcreatefiledirs');
347348
}
348349
}
349350

0 commit comments

Comments
 (0)