MDL-58297 core: Update to use new hashing functions

This commit is contained in:
Andrew Nicols 2017-03-17 15:21:59 +08:00
parent a30a04fa01
commit e6a4780452
6 changed files with 18 additions and 14 deletions

View file

@ -1379,7 +1379,7 @@ class moodle1_file_manager implements loggable {
protected function make_file_record(array $fileinfo) {
$defaultrecord = array(
'contenthash' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709', // sha1 of an empty file
'contenthash' => file_storage::hash_from_string(''),
'contextid' => $this->contextid,
'component' => $this->component,
'filearea' => $this->filearea,
@ -1422,7 +1422,7 @@ class moodle1_file_manager implements loggable {
throw new moodle1_convert_exception('file_not_readable');
}
$contenthash = sha1_file($pathname);
$contenthash = file_storage::hash_from_path($pathname);
$filesize = filesize($pathname);
$hashpath = $this->converter->get_workdir_path().'/files/'.substr($contenthash, 0, 2);
$hashfile = "$hashpath/$contenthash";

View file

@ -64,7 +64,7 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
);
$this->iconhash = sha1_file($CFG->tempdir.'/backup/'.$this->tempdir.'/moddata/unittest/4/icon.gif');
$this->iconhash = file_storage::hash_from_path($CFG->tempdir.'/backup/'.$this->tempdir.'/moddata/unittest/4/icon.gif');
copy(
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
@ -351,8 +351,8 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
$this->assertEquals('array', gettype($files['/file1.gif']));
$this->assertEquals('array', gettype($files['/sub1/.']));
$this->assertEquals('array', gettype($files['/sub1/file2.gif']));
$this->assertEquals(sha1(''), $files['/.']['contenthash']);
$this->assertEquals(sha1(''), $files['/sub1/.']['contenthash']);
$this->assertEquals(file_storage::hash_from_string(''), $files['/.']['contenthash']);
$this->assertEquals(file_storage::hash_from_string(''), $files['/sub1/.']['contenthash']);
$this->assertEquals($this->iconhash, $files['/file1.gif']['contenthash']);
$this->assertEquals($this->iconhash, $files['/sub1/file2.gif']['contenthash']);