Skip to content

Commit

Permalink
MDL-70137 cache: Write config to temp file and move into place
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and vmdef committed Nov 6, 2020
1 parent b26a5e5 commit 511dab1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cache/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ protected function config_save() {
$factory = cache_factory::instance();
$locking = $factory->create_lock_instance($lockconf);
if ($locking->lock('configwrite', 'config', true)) {
$tempcachefile = "{$cachefile}.tmp";
// Its safe to use w mode here because we have already acquired the lock.
$handle = fopen($cachefile, 'w');
$handle = fopen($tempcachefile, 'w');
fwrite($handle, $content);
fflush($handle);
fclose($handle);
$locking->unlock('configwrite', 'config');
@chmod($cachefile, $CFG->filepermissions);
@chmod($tempcachefile, $CFG->filepermissions);
rename($tempcachefile, $cachefile);
// Tell PHP to recompile the script.
core_component::invalidate_opcode_php_cache($cachefile);
} else {
Expand Down

0 comments on commit 511dab1

Please sign in to comment.