From b88f1a84bfa944b5890728ea20c8ebd888fb9b3f Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 22 Feb 2021 16:17:21 +0100 Subject: [PATCH] MDL-70901 core: @ no longer masks errors in PHP 8.0 --- backup/util/loggers/file_logger.class.php | 2 +- lib/classes/task/file_temp_cleanup_task.php | 6 +++++- lib/filestorage/file_system_filedir.php | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backup/util/loggers/file_logger.class.php b/backup/util/loggers/file_logger.class.php index d1a7554eeb2..97ae661339a 100644 --- a/backup/util/loggers/file_logger.class.php +++ b/backup/util/loggers/file_logger.class.php @@ -97,7 +97,7 @@ class file_logger extends base_logger { } else { $content = $prefix . str_repeat('  ', $depth) . htmlentities($message, ENT_QUOTES, 'UTF-8') . '
' . PHP_EOL; } - if (false === fwrite($this->fhandle, $content)) { + if (!is_resource($this->fhandle) || (false === fwrite($this->fhandle, $content))) { throw new base_logger_exception('error_writing_file', $this->fullpath); } return true; diff --git a/lib/classes/task/file_temp_cleanup_task.php b/lib/classes/task/file_temp_cleanup_task.php index 05bfd5cccbd..d4971dc84d3 100644 --- a/lib/classes/task/file_temp_cleanup_task.php +++ b/lib/classes/task/file_temp_cleanup_task.php @@ -90,7 +90,11 @@ class file_temp_cleanup_task extends scheduled_task { } else { // Return the time modified to the original date only for real files. if ($iter->isDir() && !$iter->isDot()) { - touch($node, $modifieddateobject[$node]); + try { + @touch($node, $modifieddateobject[$node]); + } catch (\Throwable $t) { + null; + } } } } diff --git a/lib/filestorage/file_system_filedir.php b/lib/filestorage/file_system_filedir.php index 3b0c509d96d..8c26da3b6dd 100644 --- a/lib/filestorage/file_system_filedir.php +++ b/lib/filestorage/file_system_filedir.php @@ -395,7 +395,10 @@ class file_system_filedir extends file_system { } rename($hashfile.'.tmp', $hashfile); chmod($hashfile, $this->filepermissions); // Fix permissions if needed. - @unlink($hashfile.'.tmp'); // Just in case anything fails in a weird way. + if (file_exists($hashfile.'.tmp')) { + // Just in case anything fails in a weird way. + @unlink($hashfile.'.tmp'); + } ignore_user_abort($prev); return array($contenthash, $filesize, $newfile);