mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-71991 files: check return value of rename when writing files
This commit is contained in:
parent
338b60f43b
commit
1af25720b0
@ -393,7 +393,14 @@ class file_system_filedir extends file_system {
|
||||
ignore_user_abort($prev);
|
||||
throw new file_exception('storedfilecannotcreatefile');
|
||||
}
|
||||
rename($hashfile.'.tmp', $hashfile);
|
||||
if (!rename($hashfile.'.tmp', $hashfile)) {
|
||||
// Something very strange went wrong.
|
||||
@unlink($hashfile . '.tmp');
|
||||
// Note, we don't try to clean up $hashfile. Almost certainly, if it exists
|
||||
// (e.g. written by another process?) it will be right, so don't wipe it.
|
||||
ignore_user_abort($prev);
|
||||
throw new file_exception('storedfilecannotcreatefile');
|
||||
}
|
||||
chmod($hashfile, $this->filepermissions); // Fix permissions if needed.
|
||||
if (file_exists($hashfile.'.tmp')) {
|
||||
// Just in case anything fails in a weird way.
|
||||
@ -470,7 +477,14 @@ class file_system_filedir extends file_system {
|
||||
ignore_user_abort($prev);
|
||||
throw new file_exception('storedfilecannotcreatefile');
|
||||
}
|
||||
rename($hashfile.'.tmp', $hashfile);
|
||||
if (!rename($hashfile.'.tmp', $hashfile)) {
|
||||
// Something very strange went wrong.
|
||||
@unlink($hashfile . '.tmp');
|
||||
// Note, we don't try to clean up $hashfile. Almost certainly, if it exists
|
||||
// (e.g. written by another process?) it will be right, so don't wipe it.
|
||||
ignore_user_abort($prev);
|
||||
throw new file_exception('storedfilecannotcreatefile');
|
||||
}
|
||||
chmod($hashfile, $this->filepermissions); // Fix permissions if needed.
|
||||
if (file_exists($hashfile.'.tmp')) {
|
||||
// Just in case anything fails in a weird way.
|
||||
|
Loading…
x
Reference in New Issue
Block a user