From 8bc9dc3b00a0018dcd7f453b7429b00179e422c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 1 Jan 2025 14:48:11 +0100 Subject: [PATCH] WP_In_Memory_Filesystem: Prevent fatal error when a streaming method is called without creating a streamer first --- .../Filesystem/WP_In_Memory_Filesystem.php | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/WordPress/Filesystem/WP_In_Memory_Filesystem.php b/src/WordPress/Filesystem/WP_In_Memory_Filesystem.php index 27050329..9e60e1b3 100644 --- a/src/WordPress/Filesystem/WP_In_Memory_Filesystem.php +++ b/src/WordPress/Filesystem/WP_In_Memory_Filesystem.php @@ -58,26 +58,40 @@ public function open_file_stream($path) { } public function next_file_chunk() { + if(!$this->last_file_reader) { + return false; + } return $this->last_file_reader->next_bytes(); } public function get_file_chunk() { + if(!$this->last_file_reader) { + return false; + } return $this->last_file_reader->get_bytes(); } public function get_streamed_file_length() { + if(!$this->last_file_reader) { + return false; + } return $this->last_file_reader->length(); } public function get_error_message() { + if(!$this->last_file_reader) { + return false; + } return $this->last_file_reader->get_last_error(); } public function close_file_stream() { - if($this->last_file_reader) { - $this->last_file_reader->close(); - $this->last_file_reader = null; + if(!$this->last_file_reader) { + return false; } + $this->last_file_reader->close(); + $this->last_file_reader = null; + return true; } public function rename($old_path, $new_path) {