From a1a72f720ea2fc70e3ed530dbf7b4fc1138e8d0b Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 15 Feb 2021 19:39:50 +0100 Subject: [PATCH] MDL-70901 core_files: @ does no mask errors in php8 anymore --- lib/filestorage/file_system_filedir.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/filestorage/file_system_filedir.php b/lib/filestorage/file_system_filedir.php index 103dcca41e562..3b0c509d96d04 100644 --- a/lib/filestorage/file_system_filedir.php +++ b/lib/filestorage/file_system_filedir.php @@ -378,7 +378,9 @@ public function add_file_from_path($pathname, $contenthash = null) { // Let's try to prevent some race conditions. $prev = ignore_user_abort(true); - @unlink($hashfile.'.tmp'); + if (file_exists($hashfile.'.tmp')) { + @unlink($hashfile.'.tmp'); + } if (!copy($pathname, $hashfile.'.tmp')) { // Borked permissions or out of disk space. @unlink($hashfile.'.tmp'); @@ -467,7 +469,10 @@ public function add_file_from_string($content) { } 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);