From a04a3c20b3d5ddb5f5acd5e5d6120b58316061ed Mon Sep 17 00:00:00 2001 From: kink Date: Thu, 3 Feb 2005 09:56:04 +0000 Subject: [PATCH] Move default_pref from data/ to config/ dir. We will check the legacy locations first in order to remain backwards compatible (an upgrade will still use the old location but a new install will use the new). When not found, do not exit with an error, just create an empty prefs file. Fix the title of the error message. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8755 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 3 +++ {data => config}/default_pref | 0 functions/file_prefs.php | 39 +++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) rename {data => config}/default_pref (100%) diff --git a/ChangeLog b/ChangeLog index e31d9435..cdf979f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -199,6 +199,9 @@ Version 1.5.1 -- CVS issue with a specific IMAP server. - In sqgetGlobalVar(), reset $value if the var is not found in the specified location. + - Move default_pref to the config/ dir, but keep checking legacy locations + first for bc. Do not fail with an error when default_pref not found, just + create an empty one. Version 1.5.0 -------------------- diff --git a/data/default_pref b/config/default_pref similarity index 100% rename from data/default_pref rename to config/default_pref diff --git a/functions/file_prefs.php b/functions/file_prefs.php index 4f8f0302..e852387e 100644 --- a/functions/file_prefs.php +++ b/functions/file_prefs.php @@ -184,35 +184,42 @@ function checkForPrefs($data_dir, $username, $filename = '') { /* Then, check if the file exists. */ if (!@file_exists($filename) ) { - /* First, check the $data_dir for the default preference file. */ + + /* If it does not exist, check for default_prefs */ + + /* First, check legacy locations: data dir */ if(substr($data_dir,-1) != '/') { $data_dir .= '/'; } $default_pref = $data_dir . 'default_pref'; - /* If it is not there, check the internal data directory. */ + /* or legacy location: internal data dir */ if (!@file_exists($default_pref)) { $default_pref = SM_PATH . 'data/default_pref'; } - /* Otherwise, report an error. */ - $errTitle = sprintf( _("Error opening %s"), $default_pref ); - if (!is_readable($default_pref)) { - $errString = $errTitle . "
\n" . - _("Default preference file not found or not readable!") . "
\n" . - _("Please contact your system administrator and report this error.") . "
\n"; - logout_error( $errString, $errTitle ); - exit; - } else if (!@copy($default_pref, $filename)) { + /* If no legacies, check where we'd expect it to be located: + * under config/ */ + if (!@file_exists($default_pref)) { + $default_pref = SM_PATH . 'config/default_pref'; + } + + /* If a default_pref file found, try to copy it, if none found, + * try to create an empty one. If that fails, report an error. + */ + if ( + ( is_readable($default_pref) && !@copy($default_pref, $filename) ) || + !@touch($filename) + ) { $uid = 'httpd'; if (function_exists('posix_getuid')){ $user_data = posix_getpwuid(posix_getuid()); $uid = $user_data['name']; } - $errString = $errTitle . '
' . - _("Could not create initial preference file!") . "
\n" . - sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) . - "
\n" . _("Please contact your system administrator and report this error.") . "
\n"; + $errTitle = _("Could not create initial preference file!"); + $errString = $errTitle . "
\n" . + sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) . "
\n" . + _("Please contact your system administrator and report this error.") . "
\n"; logout_error( $errString, $errTitle ); exit; } @@ -270,4 +277,4 @@ function getSig($data_dir, $username, $number) { } // vim: et ts=4 -?> \ No newline at end of file +?> -- 2.25.1