From ad92e2aba838eab55b3e4ee226ea7f84a0ce0649 Mon Sep 17 00:00:00 2001 From: Peter Sistrom Date: Thu, 19 Sep 2024 11:13:23 +1000 Subject: [PATCH] Issue #634: Return external accessible false is file empty or directory --- classes/local/store/object_file_system.php | 2 +- tests/object_file_system_test.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/classes/local/store/object_file_system.php b/classes/local/store/object_file_system.php index de30f1d2..38e12a2c 100644 --- a/classes/local/store/object_file_system.php +++ b/classes/local/store/object_file_system.php @@ -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); diff --git a/tests/object_file_system_test.php b/tests/object_file_system_test.php index 3621c064..6843bd6b 100644 --- a/tests/object_file_system_test.php +++ b/tests/object_file_system_test.php @@ -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();