Skip to content

Commit ab2face

Browse files
Merge pull request #640 from catalyst/issue-634-MOODLE_310_STABLE
Issue #634: Return external accessible false is file empty or directory
2 parents 3d2ce66 + 1ca731c commit ab2face

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

classes/local/store/object_file_system.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function is_file_readable_externally_by_hash($contenthash) {
249249
if ($contenthash === sha1('')) {
250250
// Files with empty size are either directories or empty.
251251
// We handle these virtually.
252-
return true;
252+
return false;
253253
}
254254

255255
$path = $this->get_external_path_from_hash($contenthash, false);

tests/object_file_system_test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ public function test_get_remote_path_from_storedfile_returns_external_path_if_du
8686
$this->assertEquals($expectedpath, $actualpath);
8787
}
8888

89+
public function test_get_remote_path_from_empty_storedfile_returns_internal_path_if_duplicated_and_preferexternal() {
90+
set_config('preferexternal', true, 'tool_objectfs');
91+
$this->reset_file_system(); // Needed to load new config.
92+
$file = $this->create_duplicated_file('');
93+
$expectedpath = $this->get_local_path_from_storedfile($file);
94+
95+
$reflection = new \ReflectionMethod(object_file_system::class, 'get_remote_path_from_storedfile');
96+
$reflection->setAccessible(true);
97+
$actualpath = $reflection->invokeArgs($this->filesystem, [$file]);
98+
99+
$this->assertEquals($expectedpath, $actualpath);
100+
}
101+
89102
public function test_get_local_path_from_hash_will_fetch_remote_if_fetchifnotfound() {
90103
$file = $this->create_remote_file();
91104
$filehash = $file->get_contenthash();

0 commit comments

Comments
 (0)