From 1a6cb937c7841ade46b188c6c33cd40220833939 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Fri, 14 Oct 2016 08:46:42 -0300 Subject: Change safe_write_file $content parameter to accept an array --- src/etc/inc/config.lib.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/etc/inc/config.lib.inc b/src/etc/inc/config.lib.inc index 1b2cc32..28a7a36 100644 --- a/src/etc/inc/config.lib.inc +++ b/src/etc/inc/config.lib.inc @@ -485,7 +485,7 @@ function convert_config() { * process, them renaming the temporary file over the original. * INPUTS * $filename - string containing the filename of the file to write - * $content - string containing the file content to write to file + * $content - string or array containing the file content to write to file * $force_binary - boolean denoting whether we should force binary * mode writing. * RESULT @@ -500,7 +500,15 @@ function safe_write_file($file, $content, $force_binary = false) { // Unable to open temporary file for writing return false; } - if (!fwrite($fd, $content)) { + if (is_array($content)) { + foreach ($content as $line) { + if (!fwrite($fd, $line . "\n")) { + // Unable to write to temporary file + fclose($fd); + return false; + } + } + } elseif (!fwrite($fd, $content)) { // Unable to write to temporary file fclose($fd); return false; -- cgit v1.1