Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.421
diff -u -p -r1.421 bootstrap.inc
--- includes/bootstrap.inc	27 Sep 2010 01:14:10 -0000	1.421
+++ includes/bootstrap.inc	29 Sep 2010 02:47:38 -0000
@@ -560,7 +560,7 @@ function drupal_settings_initialize() {
   global $base_url, $base_path, $base_root;
 
   // Export the following settings.php variables to the global namespace
-  global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;
+  global $databases, $cookie_domain, $conf, $install_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;
   $conf = array();
 
   if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) {
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1228
diff -u -p -r1.1228 common.inc
--- includes/common.inc	26 Sep 2010 23:31:35 -0000	1.1228
+++ includes/common.inc	29 Sep 2010 02:47:39 -0000
@@ -197,20 +197,24 @@ function drupal_get_region_content($regi
 /**
  * Get the name of the currently active install profile.
  *
- * When this function is called during Drupal's initial installation process,
- * the name of the profile that's about to be installed is stored in the global
- * installation state. At all other times, the standard Drupal systems variable
- * table contains the name of the current profile, and we can call variable_get()
- * to determine what one is active.
+ * This value is stored in the settings.php file generated during installation.
+ *
+ * Because we need to have this information before the database connection is 
+ * initialized, to correctly determine where to search for modules and themes,
+ * we can not use the variable system to store this value.
+ *
+ * If this function is called during the initial installation process,
+ * the global variable will be initialized to the profile requested by the user
+ * and then stored in the settings file for future use.
  *
  * @return $profile
  *   The name of the install profile.
  */
 function drupal_get_profile() {
-  global $install_state;
+  global $install_profile;
 
-  if (isset($install_state['parameters']['profile'])) {
-    $profile = $install_state['parameters']['profile'];
+  if (!empty($install_profile)) {
+    $profile = $install_profile;
   }
   else {
     $profile = variable_get('install_profile', 'standard');
Index: includes/install.core.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.core.inc,v
retrieving revision 1.34
diff -u -p -r1.34 install.core.inc
--- includes/install.core.inc	24 Sep 2010 21:36:22 -0000	1.34
+++ includes/install.core.inc	29 Sep 2010 02:47:39 -0000
@@ -239,7 +239,10 @@ function install_begin_request(&$install
   drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
 
   // This must go after drupal_bootstrap(), which unsets globals!
-  global $conf;
+  global $conf, $install_profile;
+  if (!empty($install_profile)) {
+    $install_state['parameters']['profile'] = $install_profile;
+  }
 
   require_once DRUPAL_ROOT . '/modules/system/system.install';
   require_once DRUPAL_ROOT . '/includes/common.inc';
@@ -526,13 +529,22 @@ function install_tasks($install_state) {
   // Determine whether translation import tasks will need to be performed.
   $needs_translations = count($install_state['locales']) > 1 && !empty($install_state['parameters']['locale']) && $install_state['parameters']['locale'] != 'en';
 
+  // Check whether the install profile selected is a valid choice.
+  $valid_profile = FALSE;
+  if (!empty($install_state['parameters']['profile'])) {
+    $profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
+    if (is_file($profile_file)) {
+      $valid_profile = TRUE;
+    }
+  }
+
   // Start with the core installation tasks that run before handing control
   // to the install profile.
   $tasks = array(
     'install_select_profile' => array(
       'display_name' => st('Choose profile'),
       'display' => count($install_state['profiles']) != 1,
-      'run' => INSTALL_TASK_RUN_IF_REACHED,
+      'run' => $valid_profile ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_REACHED,
     ),
     'install_select_locale' => array(
       'display_name' => st('Choose language'),
@@ -594,15 +606,13 @@ function install_tasks($install_state) {
     ),
   );
 
+
   // Allow the installation profile to modify the full list of tasks.
-  if (!empty($install_state['parameters']['profile'])) {
-    $profile_file = DRUPAL_ROOT . '/profiles/' . $install_state['parameters']['profile'] . '/' . $install_state['parameters']['profile'] . '.profile';
-    if (is_file($profile_file)) {
-      include_once $profile_file;
-      $function = $install_state['parameters']['profile'] . '_install_tasks_alter';
-      if (function_exists($function)) {
-        $function($tasks, $install_state);
-      }
+  if ($valid_profile) {
+    include_once $profile_file;
+    $function = $install_state['parameters']['profile'] . '_install_tasks_alter';
+    if (function_exists($function)) {
+      $function($tasks, $install_state);
     }
   }
 
@@ -1014,6 +1024,11 @@ function install_settings_form_submit($f
     'value'    => drupal_hash_base64(drupal_random_bytes(55)),
     'required' => TRUE,
   );
+  $settings['install_profile'] = array(
+    'value' => $install_state['parameters']['profile'],
+    'required' => TRUE
+  );
+
   drupal_rewrite_settings($settings);
   // Indicate that the settings file has been verified, and check the database
   // for the last completed task, now that we have a valid connection. This
@@ -1530,9 +1545,6 @@ function install_finished(&$install_stat
   // Register actions declared by any modules.
   actions_synchronize();
 
-  // Remember the profile which was used.
-  variable_set('install_profile', drupal_get_profile());
-
   // Install profiles are always loaded last
   db_update('system')
     ->fields(array('weight' => 1000))
Index: includes/update.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/update.inc,v
retrieving revision 1.69
diff -u -p -r1.69 update.inc
--- includes/update.inc	25 Sep 2010 18:10:53 -0000	1.69
+++ includes/update.inc	29 Sep 2010 02:47:40 -0000
@@ -354,12 +354,31 @@ function update_fix_d7_requirements() {
 
   // Rewrite the settings.php file if necessary, see
   // update_prepare_d7_bootstrap().
-  global $update_rewrite_settings, $db_url, $db_prefix;
+  global $update_rewrite_settings, $db_url, $db_prefix, $install_profile;
   if (!empty($update_rewrite_settings)) {
     $databases = update_parse_db_url($db_url, $db_prefix);
     $salt = drupal_hash_base64(drupal_random_bytes(55));
     file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ";\n\$drupal_hash_salt = '$salt';", FILE_APPEND);
+
+    // The install profile was renamed from 'default' to 'standard'.
+    // This change was originally handled in system_update_7049(), 
+    // but because we no longer use a variable to store the profile name,
+    // it is no longer necessary.
+    $profile = variable_get('install_profile', 'standard');
+    if ($profile == 'default') {
+      $profile = 'standard';
+    }
+
+    file_put_contents(conf_path() . '/settings.php', "\n" . '$install_profile = ' . var_export($profile, TRUE) . ';', FILE_APPEND);
+
+    // We modify the $install_profile global, so that future calls to drupal_get_profile() will return the correct value,
+    //  because the settings.php file has already been loaded at this point.
+    $install_profile = $profile;
+
+    // Remove the unnecessary variable.
+    variable_del('install_profile');
   }
+
   if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
     // Change 6.x system table field values to 7.x equivalent.
     // Change field values.
Index: modules/node/node.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.install,v
retrieving revision 1.57
diff -u -p -r1.57 node.install
--- modules/node/node.install	28 Sep 2010 03:30:37 -0000	1.57
+++ modules/node/node.install	29 Sep 2010 02:47:40 -0000
@@ -410,7 +410,7 @@ function node_update_dependencies() {
   // Node update 7006 migrates node data to fields and therefore must run after
   // the Field module has been enabled, but before upgrading field data.
   $dependencies['node'][7006] = array(
-    'system' => 7049,
+    'system' => 7048,
     // It must also run after filter_update_7000() because it needs to query
     // the list of existing text formats.
     'filter' => 7000,
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.238
diff -u -p -r1.238 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	28 Sep 2010 03:30:37 -0000	1.238
+++ modules/simpletest/drupal_web_test_case.php	29 Sep 2010 02:47:40 -0000
@@ -591,7 +591,7 @@ class DrupalUnitTestCase extends DrupalT
    * method.
    */
   protected function setUp() {
-    global $conf;
+    global $conf, $install_profile;
 
     // Store necessary current values before switching to the test environment.
     $this->originalFileDirectory = variable_get('file_public_path', conf_path() . '/files');
@@ -1166,7 +1166,7 @@ class DrupalWebTestCase extends DrupalTe
    *   either a single array or a variable number of string arguments.
    */
   protected function setUp() {
-    global $user, $language, $conf;
+    global $user, $language, $conf, $install_profile;
 
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
     $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
@@ -1236,8 +1236,8 @@ class DrupalWebTestCase extends DrupalTe
     variable_set('file_private_path', $private_files_directory);
     variable_set('file_temporary_path', $temp_files_directory);
 
-    // Include the testing profile.
-    variable_set('install_profile', $this->profile);
+    // Include the default profile.
+    $install_profile = $this->profile;
     $profile_details = install_profile_info($this->profile, 'en');
 
     // Install the modules specified by the testing profile.
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.509
diff -u -p -r1.509 system.install
--- modules/system/system.install	25 Sep 2010 18:10:53 -0000	1.509
+++ modules/system/system.install	29 Sep 2010 02:47:40 -0000
@@ -2349,15 +2349,6 @@ function system_update_7048() {
 }
 
 /**
- * Rename 'Default' profile to 'Standard.'
- */
-function system_update_7049() {
-  if (variable_get('install_profile', 'standard') == 'default') {
-    variable_set('install_profile', 'standard');
-  }
-}
-
-/**
  * Change {batch}.id column from serial to regular int.
  */
 function system_update_7050() {
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.48
diff -u -p -r1.48 taxonomy.install
--- modules/taxonomy/taxonomy.install	28 Sep 2010 03:30:37 -0000	1.48
+++ modules/taxonomy/taxonomy.install	29 Sep 2010 02:47:41 -0000
@@ -246,7 +246,7 @@ function taxonomy_update_dependencies() 
   // run after the Field module has been enabled, but before upgrading field
   // data.
   $dependencies['taxonomy'][7002] = array(
-    'system' => 7049,
+    'system' => 7048,
   );
   $dependencies['user'][7006] = array(
     'taxonomy' => 7002,
Index: sites/default/default.settings.php
===================================================================
RCS file: /cvs/drupal/drupal/sites/default/default.settings.php,v
retrieving revision 1.50
diff -u -p -r1.50 default.settings.php
--- sites/default/default.settings.php	8 Aug 2010 19:35:49 -0000	1.50
+++ sites/default/default.settings.php	29 Sep 2010 02:47:41 -0000
@@ -213,6 +213,15 @@ $update_free_access = FALSE;
 $drupal_hash_salt = '';
 
 /**
+ * Install profile:
+ *
+ * Drupal can be installed with one of several install profiles, which
+ * will provide some initial configuration and an additional location for
+ * modules and themes to be loaded from.
+ */
+ $install_profile = '';
+
+/**
  * Base URL (optional).
  *
  * If Drupal is generating incorrect URLs on your site, which could
