mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 18:36:42 +02:00
MDL-32825 try to improve atomicity of cache file operations in themes and javascript
This commit is contained in:
parent
4dd63b6d70
commit
979d320722
6 changed files with 105 additions and 39 deletions
|
@ -71,10 +71,25 @@ function css_store_css(theme_config $theme, $csspath, array $cssfiles) {
|
|||
$css = $theme->post_process(css_minify_css($cssfiles));
|
||||
}
|
||||
|
||||
check_dir_exists(dirname($csspath));
|
||||
$fp = fopen($csspath, 'w');
|
||||
fwrite($fp, $css);
|
||||
fclose($fp);
|
||||
clearstatcache();
|
||||
if (!file_exists(dirname($csspath))) {
|
||||
@mkdir(dirname($csspath), $CFG->directorypermissions, true);
|
||||
}
|
||||
|
||||
// Prevent serving of incomplete file from concurrent request,
|
||||
// the rename() should be more atomic than fwrite().
|
||||
ignore_user_abort(true);
|
||||
if ($fp = fopen($csspath.'.tmp', 'xb')) {
|
||||
fwrite($fp, $css);
|
||||
fclose($fp);
|
||||
rename($csspath.'.tmp', $csspath);
|
||||
@chmod($csspath, $CFG->filepermissions);
|
||||
@unlink($csspath.'.tmp'); // just in case anything fails
|
||||
}
|
||||
ignore_user_abort(false);
|
||||
if (connection_aborted()) {
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue