MDL-43390 files: Only lock when locking is not prevented
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user