瀏覽代碼

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.

Thijs Kinkhorst 20 年之前
父節點
當前提交
92432b64c6
共有 3 個文件被更改,包括 26 次插入16 次删除
  1. 3 0
      ChangeLog
  2. 0 0
      config/default_pref
  3. 23 16
      functions/file_prefs.php

+ 3 - 0
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
 --------------------

+ 0 - 0
data/default_pref → config/default_pref


+ 23 - 16
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 . "<br />\n" .
-                         _("Default preference file not found or not readable!") . "<br />\n" .
-                         _("Please contact your system administrator and report this error.") . "<br />\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 . '<br />' .
-                       _("Could not create initial preference file!") . "<br />\n" .
-                       sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) .
-                       "<br />\n" . _("Please contact your system administrator and report this error.") . "<br />\n";
+            $errTitle = _("Could not create initial preference file!");
+            $errString = $errTitle . "<br />\n" .
+                       sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) . "<br />\n" .
+                       _("Please contact your system administrator and report this error.") . "<br />\n";
             logout_error( $errString, $errTitle );
             exit;
         }
@@ -270,4 +277,4 @@ function getSig($data_dir, $username, $number) {
 }
 
 // vim: et ts=4
-?>
+?>