diff --git a/lib/filestorage/file_system_filedir.php b/lib/filestorage/file_system_filedir.php index b307a5dc758..ff7a4400d5f 100644 --- a/lib/filestorage/file_system_filedir.php +++ b/lib/filestorage/file_system_filedir.php @@ -421,12 +421,13 @@ class file_system_filedir extends file_system { @unlink($hashfile.'.tmp'); if (!copy($pathname, $hashfile.'.tmp')) { // Borked permissions or out of disk space. + @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); } - if (filesize($hashfile.'.tmp') !== $filesize) { - // This should not happen. - unlink($hashfile.'.tmp'); + if (sha1_file($hashfile.'.tmp') !== $contenthash) { + // Highly unlikely edge case, but this can happen on an NFS volume with no space remaining. + @unlink($hashfile.'.tmp'); ignore_user_abort($prev); throw new file_exception('storedfilecannotcreatefile'); }