Index: theme.php
===================================================================
--- theme.php	(revision 17436)
+++ theme.php	(working copy)
@@ -592,52 +592,51 @@
 		if ( !$themes_dir )
 			return false;
 
-		while ( ($theme_dir = readdir($themes_dir)) !== false ) {
-			if ( is_dir($theme_root . '/' . $theme_dir) && is_readable($theme_root . '/' . $theme_dir) ) {
-				if ( $theme_dir[0] == '.' || $theme_dir == 'CVS' )
-					continue;
+		while ( ( $theme_dir = readdir( $themes_dir ) ) !== false ) {
+			$subdir = "$theme_root/$theme_dir";
+			
+			if ( '.' == $theme_dir[0] || !is_dir( $subdir ) || ! is_readable( $subdir ) )
+				continue;
+			
+			$stylish_dir = @opendir( $subdir );
+			$found_stylesheet = false;
 
-				$stylish_dir = @opendir($theme_root . '/' . $theme_dir);
-				$found_stylesheet = false;
-
-				while ( ($theme_file = readdir($stylish_dir)) !== false ) {
-					if ( $theme_file == 'style.css' ) {
-						$theme_files[$theme_dir] = array( 'theme_file' => $theme_dir . '/' . $theme_file, 'theme_root' => $theme_root );
-						$found_stylesheet = true;
-						break;
-					}
+			while ( ( $theme_file = readdir( $stylish_dir ) ) !== false ) {
+				if ( $theme_file == 'style.css' ) {
+					$theme_files[$theme_dir] = array( 'theme_file' => $theme_dir . '/' . $theme_file, 'theme_root' => $theme_root );
+					$found_stylesheet = true;
+					break;
 				}
-				@closedir($stylish_dir);
+			}
+			@closedir($stylish_dir);
 
-				if ( !$found_stylesheet ) { // look for themes in that dir
-					$subdir = "$theme_root/$theme_dir";
-					$subdir_name = $theme_dir;
-					$theme_subdirs = @opendir( $subdir );
+			if ( !$found_stylesheet ) { // look for themes in that dir
+				$subdir_name = $theme_dir;
+				$theme_subdirs = @opendir( $subdir );
+				$found_subdir_themes = false;
+				
+				while ( ( $theme_subdir = readdir( $theme_subdirs ) ) !== false ) {
+					$sub_subdir = "$subdir/$theme_subdir";
+					
+					if ( '.' == $theme_subdir[0] || !is_dir( $sub_subdir ) || !is_readable( $sub_subdir ) )
+						continue;
 
-					$found_subdir_themes = false;
-					while ( ($theme_subdir = readdir($theme_subdirs)) !== false ) {
-						if ( is_dir( $subdir . '/' . $theme_subdir) && is_readable($subdir . '/' . $theme_subdir) ) {
-							if ( $theme_subdir[0] == '.' || $theme_subdir == 'CVS' )
-								continue;
+					$stylish_dir = @opendir( $sub_subdir );
+					$found_stylesheet = false;
 
-							$stylish_dir = @opendir($subdir . '/' . $theme_subdir);
-							$found_stylesheet = false;
-
-							while ( ($theme_file = readdir($stylish_dir)) !== false ) {
-								if ( $theme_file == 'style.css' ) {
-									$theme_files["$theme_dir/$theme_subdir"] = array( 'theme_file' => $subdir_name . '/' . $theme_subdir . '/' . $theme_file, 'theme_root' => $theme_root );
-									$found_stylesheet = true;
-									$found_subdir_themes = true;
-									break;
-								}
-							}
-							@closedir($stylish_dir);
+					while ( ($theme_file = readdir($stylish_dir)) !== false ) {
+						if ( $theme_file == 'style.css' ) {
+							$theme_files["$theme_dir/$theme_subdir"] = array( 'theme_file' => $subdir_name . '/' . $theme_subdir . '/' . $theme_file, 'theme_root' => $theme_root );
+							$found_stylesheet = true;
+							$found_subdir_themes = true;
+							break;
 						}
 					}
-					@closedir($theme_subdirs);
-					if ( !$found_subdir_themes )
-						$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
+					@closedir($stylish_dir);
 				}
+				@closedir($theme_subdirs);
+				if ( !$found_subdir_themes )
+					$wp_broken_themes[$theme_dir] = array('Name' => $theme_dir, 'Title' => $theme_dir, 'Description' => __('Stylesheet is missing.'));
 			}
 		}
 		@closedir( $themes_dir );
