Skip to content

Commit

Permalink
Merge pull request #639 from catalyst/issue-634
Browse files Browse the repository at this point in the history
Issue #634: Return external accessible false is file empty or directory
  • Loading branch information
brendanheywood authored Oct 8, 2024
2 parents eaabc7e + ad92e2a commit 83b2053
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/local/store/object_file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function is_file_readable_externally_by_hash($contenthash) {
if ($contenthash === sha1('')) {
// Files with empty size are either directories or empty.
// We handle these virtually.
return true;
return false;
}

$path = $this->get_external_path_from_hash($contenthash, false);
Expand Down
13 changes: 13 additions & 0 deletions tests/object_file_system_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ public function test_get_remote_path_from_storedfile_returns_external_path_if_du
$this->assertEquals($expectedpath, $actualpath);
}

public function test_get_remote_path_from_empty_storedfile_returns_internal_path_if_duplicated_and_preferexternal() {
set_config('preferexternal', true, 'tool_objectfs');
$this->reset_file_system(); // Needed to load new config.
$file = $this->create_duplicated_file('');
$expectedpath = $this->get_local_path_from_storedfile($file);

$reflection = new \ReflectionMethod(object_file_system::class, 'get_remote_path_from_storedfile');
$reflection->setAccessible(true);
$actualpath = $reflection->invokeArgs($this->filesystem, [$file]);

$this->assertEquals($expectedpath, $actualpath);
}

public function test_get_local_path_from_hash_will_fetch_remote_if_fetchifnotfound() {
$file = $this->create_remote_file();
$filehash = $file->get_contenthash();
Expand Down

0 comments on commit 83b2053

Please sign in to comment.