Skip to content

Commit

Permalink
Issue #634: Return external accessible false is file empty or directory
Browse files Browse the repository at this point in the history
  • Loading branch information
petersistrom committed Sep 19, 2024
1 parent eaabc7e commit ff4f7ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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
17 changes: 15 additions & 2 deletions tests/object_file_system_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,21 @@ public function test_get_remote_path_from_storedfile_returns_external_path_if_no
public function test_get_remote_path_from_storedfile_returns_external_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_external_path_from_storedfile($file);
$file = $this->create_local_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_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);
Expand Down

0 comments on commit ff4f7ed

Please sign in to comment.