Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #634: Return external accessible false is file empty or directory #639

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading