From 10ccdfb8cdbacf1c7313a623f9e82ecd36ba6cee Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 14 Jul 2014 12:13:41 +0800 Subject: [PATCH] MDL-43390 files: Only lock when locking is not prevented --- lib/filestorage/file_storage.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 32fec854601..0e92edfe87a 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -1721,6 +1721,8 @@ class file_storage { * @return array (contenthash, filesize, newfile) */ public function add_string_to_pool($content) { + global $CFG; + $contenthash = sha1($content); $filesize = strlen($content); // binary length @@ -1755,7 +1757,13 @@ class file_storage { // Hopefully this works around most potential race conditions. $prev = ignore_user_abort(true); - $newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX); + + if (!empty($CFG->preventfilelocking)) { + $newsize = file_put_contents($hashfile.'.tmp', $content); + } else { + $newsize = file_put_contents($hashfile.'.tmp', $content, LOCK_EX); + } + if ($newsize === false) { // Borked permissions most likely. ignore_user_abort($prev);