From ff4f7ed10f9e85b0ca7d914c6c84784b4d969ae7 Mon Sep 17 00:00:00 2001 From: Peter Sistrom Date: Thu, 19 Sep 2024 11:07:46 +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 | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) 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..0119f23e 100644 --- a/tests/object_file_system_test.php +++ b/tests/object_file_system_test.php @@ -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);