mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-58297 core: Update to use new hashing functions
This commit is contained in:
parent
a30a04fa01
commit
e6a4780452
6 changed files with 18 additions and 14 deletions
|
@ -571,7 +571,7 @@ class repository_filesystem extends repository {
|
|||
$fs = get_file_storage();
|
||||
$issyncing = true;
|
||||
if (file_extension_in_typegroup($filepath, 'web_image')) {
|
||||
$contenthash = sha1_file($filepath);
|
||||
$contenthash = file_storage::hash_from_path($filepath);
|
||||
if ($file->get_contenthash() == $contenthash) {
|
||||
// File did not change since the last synchronisation.
|
||||
$filesize = filesize($filepath);
|
||||
|
@ -581,9 +581,10 @@ class repository_filesystem extends repository {
|
|||
}
|
||||
} else {
|
||||
// Update only file size so file will NOT be copied into moodle filepool.
|
||||
$emptyfile = $contenthash = sha1('');
|
||||
$currentcontenthash = $file->get_contenthash();
|
||||
if ($currentcontenthash !== $emptyfile && $currentcontenthash === sha1_file($filepath)) {
|
||||
if ($file->compare_to_string('') || !$file->compare_to_path($filepath)) {
|
||||
// File is not synchronized or the file has changed.
|
||||
$contenthash = file_storage::hash_from_string('');
|
||||
} else {
|
||||
// File content was synchronised and has not changed since then, leave it.
|
||||
$contenthash = null;
|
||||
}
|
||||
|
@ -701,7 +702,7 @@ class repository_filesystem extends repository {
|
|||
// File is not found or is not readable.
|
||||
return null;
|
||||
}
|
||||
$filename = sha1($filecontents);
|
||||
$filename = file_storage::hash_from_string($filecontents);
|
||||
|
||||
// Try to get generated thumbnail for this file.
|
||||
$fs = get_file_storage();
|
||||
|
@ -751,7 +752,7 @@ class repository_filesystem extends repository {
|
|||
foreach ($files as $filepath => $filesinpath) {
|
||||
if ($filecontents = @file_get_contents($this->get_rootpath() . trim($filepath, '/'))) {
|
||||
// The 'filename' in Moodle file storage is contenthash of the file in filesystem repository.
|
||||
$filename = sha1($filecontents);
|
||||
$filename = file_storage::hash_from_string($filecontents);
|
||||
foreach ($filesinpath as $file) {
|
||||
if ($file->get_filename() !== $filename && $file->get_filename() !== '.') {
|
||||
// Contenthash does not match, this is an old thumbnail.
|
||||
|
|
|
@ -1722,7 +1722,7 @@ abstract class repository implements cacheable_object {
|
|||
// size, and a contenthash which does not related to empty content.
|
||||
// If thereis no file size, or the contenthash is for an empty file, then the file has
|
||||
// yet to be successfully downloaded.
|
||||
$contentexists = $file->get_filesize() && $file->get_contenthash() !== sha1('');
|
||||
$contentexists = $file->get_filesize() && !$file->compare_to_string('');
|
||||
|
||||
if (!$file->get_status() && $contentexists) {
|
||||
// we already have the content in moodle filepool and it was synchronised recently.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue