Index: includes/install.core.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.core.inc,v
retrieving revision 1.25
diff -u -r1.25 install.core.inc
--- includes/install.core.inc	2 Jul 2010 15:32:10 -0000	1.25
+++ includes/install.core.inc	13 Jul 2010 02:41:00 -0000
@@ -421,16 +421,36 @@
 }
 
 /**
- * Replace values in settings.php with values in the submitted array.
+ * Writes a settings.php file with content from default.settings.php replaced by values from the passed in settings array.
  *
  * @param $settings
  *   An array of settings that need to be updated.
  */
 function drupal_rewrite_settings($settings = array(), $prefix = '') {
-  $default_settings = 'sites/default/default.settings.php';
+  $default_settings_file = 'sites/default/default.settings.php';
   drupal_static_reset('conf_path');
   $settings_file = conf_path(FALSE) . '/' . $prefix . 'settings.php';
 
+  $buffer = drupal_generate_settings_file($default_settings_file, $settings);
+  $fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w');
+  if ($fp && fwrite($fp, $buffer) === FALSE) {
+    throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
+  }
+}
+
+/**
+ * Generates content for a new settings.php file with content from another settings.php file replaced by values from the passed in settings array.
+ *
+ * @param $base_file
+ *   A path to an existing settings.php file (e.g.,
+ *   'sites/default/default.settings.php').
+ * @param $settings
+ *   An array of settings that need to be updated.
+ *
+ * @return
+ *   A string that can be output to a new settings.php file.
+ */
+function drupal_generate_settings_file($base_file, $settings = array()) {
   // Build list of setting names and insert the values into the global namespace.
   $keys = array();
   foreach ($settings as $setting => $data) {
@@ -440,7 +460,7 @@
 
   $buffer = NULL;
   $first = TRUE;
-  if ($fp = fopen(DRUPAL_ROOT . '/' . $default_settings, 'r')) {
+  if ($fp = fopen(DRUPAL_ROOT . '/' . $base_file, 'r')) {
     // Step line by line through settings.php.
     while (!feof($fp)) {
       $line = fgets($fp);
@@ -487,15 +507,12 @@
         $buffer .= "\$$setting = " . var_export($data['value'], TRUE) . ";\n";
       }
     }
-
-    $fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w');
-    if ($fp && fwrite($fp, $buffer) === FALSE) {
-      throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
     }
-  }
   else {
-    throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $default_settings)));
+    throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $base_file)));
   }
+
+  return $buffer;
 }
 
 /**
