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);