### Eclipse Workspace Patch 1.0
#P wordpress-trunk bare
Index: wp-admin/includes/upgrade.php
===================================================================
--- wp-admin/includes/upgrade.php	(revision 17523)
+++ wp-admin/includes/upgrade.php	(working copy)
@@ -1695,33 +1695,28 @@
 
 	// Copy files from the default theme to the site theme.
 	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
+	
+	if( ! @make_directory_file_copy( $default_dir, $site_dir ) ) 
+		return;
 
-	$theme_dir = @ opendir($default_dir);
-	if ($theme_dir) {
-		while(($theme_file = readdir( $theme_dir )) !== false) {
-			if (is_dir("$default_dir/$theme_file"))
-				continue;
-			if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
-				return;
-			chmod("$site_dir/$theme_file", 0777);
-		}
-	}
-	@closedir($theme_dir);
-
 	// Rewrite the theme header.
-	$stylelines = explode("\n", implode('', file("$site_dir/style.css")));
-	if ($stylelines) {
-		$f = fopen("$site_dir/style.css", 'w');
+	$stylelines = file( "$site_dir/style.css", FILE_IGNORE_NEW_LINES );
+	if ( $stylelines ) {
+		$headers = array(
+			'Theme Name:' => $theme_name,
+			'Theme URI:' => __get_option( 'url' ),
+			'Description:' => 'Your theme.',
+			'Version:' => '1',
+			'Author:' => 'You'
+		);
 
-		foreach ($stylelines as $line) {
-			if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name;
-			elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url');
-			elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.';
-			elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1';
-			elseif (strpos($line, 'Author:') !== false) $line = 'Author: You';
-			fwrite($f, $line . "\n");
-		}
-		fclose($f);
+		foreach ( $stylelines as &$line )
+			foreach ( $headers as $header => $value )
+				if ( strpos( $line, $header ) !== false )
+					$line = $header . ' ' . $value
+			;
+
+		file_put_contents( "$site_dir/style.css", implode( "\n", $stylelines ) );
 	}
 
 	// Copy the images.
@@ -1730,17 +1725,31 @@
 		return false;
 	}
 
-	$images_dir = @ opendir("$default_dir/images");
-	if ($images_dir) {
-		while(($image = readdir($images_dir)) !== false) {
-			if (is_dir("$default_dir/images/$image"))
+	@make_directory_file_copy( "$default_dir/images", "$site_dir/images" );
+}
+
+/**
+ * Copy files from origin directory into target directory
+ * and set their mode to 0777.
+ * 
+ * @param $origin string Directory to copy files from
+ * @param $target string Directory to copy files to
+ * @return bool false if unable to copy one of the files
+ */
+function make_directory_file_copy($origin, $target, $mode = 0777) {
+	if ( $handle = opendir( $origin ) ) {
+		while( $file = readdir( $handle ) ) {
+			$path_from = "$origin/$file";
+			if ( is_dir( $path_from ) )
 				continue;
-			if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
-				return;
-			chmod("$site_dir/images/$image", 0777);
+			$path_to = "$target/$file";
+			if ( ! copy( $path_from, $path_to ) )
+				return false;
+			chmod( $path_to , $mode );
 		}
+		closedir( $handle );
 	}
-	@closedir($images_dir);
+	return true;
 }
 
 // Create a site theme from the default theme.
