From 10b94ce2ef4d45476e44b261fe906dd69174e983 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 11 Sep 2019 23:44:59 +0100 Subject: [PATCH] Use tempnam() instead of tmpfile() when unpacking extra data It seems that some people were experiencing some strange issues with stream_get_meta_data($handle)["uri"] - hrm :thinking: --- core/07-unpack.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/core/07-unpack.php b/core/07-unpack.php index cb87b4e..8e875fc 100644 --- a/core/07-unpack.php +++ b/core/07-unpack.php @@ -22,11 +22,12 @@ if(!file_exists($paths->extra_data_directory) || http_response_code(503); exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! It looks like $settings->sitename isn't able to change the last modified time of the extra data directory.

$error_message_help")); } - - $temp_file = tmpfile(); + + $temp_filename = tempnam(sys_get_temp_dir(), "PeppermintExtract"); + $temp_file = fopen($temp_filename, "wb+"); if($temp_file === false) { http_response_code(503); - exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to create a new temporary file with tmpfile(). Perhaps your server is mis-configured?

")); + exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to create a new temporary file with tempnam(). Perhaps your server is mis-configured?

")); } $source = fopen(__FILE__, "r"); if($source === false) { @@ -36,17 +37,14 @@ if(!file_exists($paths->extra_data_directory) || fseek($source, __COMPILER_HALT_OFFSET__); stream_copy_to_stream($source, $temp_file); - - $temp_filename = stream_get_meta_data($temp_file)["uri"]; + fclose($temp_file); $extractor = new ZipArchive(); $extractor->open($temp_filename); $extractor->extractTo($paths->extra_data_directory); $extractor->close(); - if(fclose($temp_file) === false) { - http_response_code(503); - exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "

Oops! $settings->sitename wasn't able to close the temporary file that it created with tmpfile(). Perhaps your server is mis-configured?

")); - } + + unlink($temp_filename); unset($error_message_help); }