From 879827d6fa2934347fbd8fb95f3eab91fdf24b91 Mon Sep 17 00:00:00 2001 From: Mark Nielsen Date: Thu, 31 Aug 2017 15:47:00 -0700 Subject: [PATCH] MDL-60001 core_files: Use local file for gzopen The gzopen method does not appear to support file streams. --- lib/filestorage/file_system.php | 7 ++++++- lib/filestorage/tests/file_system_test.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/filestorage/file_system.php b/lib/filestorage/file_system.php index 3da41716ef65f..8134a8002f424 100644 --- a/lib/filestorage/file_system.php +++ b/lib/filestorage/file_system.php @@ -478,7 +478,12 @@ abstract public function add_file_from_string($content); * @return resource file handle */ public function get_content_file_handle(stored_file $file, $type = stored_file::FILE_HANDLE_FOPEN) { - $path = $this->get_remote_path_from_storedfile($file); + if ($type === stored_file::FILE_HANDLE_GZOPEN) { + // Local file required for gzopen. + $path = $this->get_local_path_from_storedfile($file, true); + } else { + $path = $this->get_remote_path_from_storedfile($file); + } return self::get_file_handle_for_path($path, $type); } diff --git a/lib/filestorage/tests/file_system_test.php b/lib/filestorage/tests/file_system_test.php index adf539f5f5d88..73a94dc9f548a 100644 --- a/lib/filestorage/tests/file_system_test.php +++ b/lib/filestorage/tests/file_system_test.php @@ -904,8 +904,8 @@ public function test_get_content_file_handle_gz() { $filecontent = 'example content'; $file = $this->get_stored_file($filecontent); - $fs = $this->get_testable_mock(['get_remote_path_from_storedfile']); - $fs->method('get_remote_path_from_storedfile') + $fs = $this->get_testable_mock(['get_local_path_from_storedfile']); + $fs->method('get_local_path_from_storedfile') ->willReturn(__DIR__ . "/fixtures/test.tgz"); // Note: We are unable to determine the mode in which the $fh was opened.