From 82c7f4b89d4c8fa86caca25d77b2c8e2b9738349 Mon Sep 17 00:00:00 2001 From: ralf Date: Sat, 5 Mar 2022 15:57:18 +0200 Subject: [PATCH] rename header.inc.php to header-backup.inc.php before updating it and rename it back, if update fails --- doc/rpm-build/post_install.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/rpm-build/post_install.php b/doc/rpm-build/post_install.php index c9a4a838d1..6a6c976ac8 100755 --- a/doc/rpm-build/post_install.php +++ b/doc/rpm-build/post_install.php @@ -526,9 +526,15 @@ function patch_header($filename,&$user,$password) } //error_log(__FUNCTION__."('$filename', '$user', '$password') header_admin_password was '$pmatches[1]'"); - file_put_contents($filename,$header_new=preg_replace('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m", - // $ in password needs to be escaped as they otherwise address captures in the regualar expression - "\$GLOBALS['egw_info']['server']['header_admin_password'] = '".str_replace('$', '\\$', $password)."';",$header)); + $header_new = preg_replace('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m", + // $ in password needs to be escaped as they otherwise address captures in the regular expression + "\$GLOBALS['egw_info']['server']['header_admin_password'] = '".str_replace('$', '\\$', $password)."';",$header); + rename($filename, $backup=substr($filename, 0, -8).'-backup.inc.php'); + if (strlen($header_new) !== file_put_contents($filename, $header_new)) + { + rename($backup, $filename); + bail_out(99, "Failed to update $filename, maybe disk full!"); + } /*$xmatches = null; preg_match('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",$header_new,$xmatches); @@ -923,4 +929,4 @@ function _size_with_unit($_size) $size *= 1024; } return $size; -} +} \ No newline at end of file