? .cache
? .project
? .settings
? drupal_image_handling_1.patch
? file_373502.patch
? includes/junk
? sites/all/modules/cvs_deploy
? sites/all/modules/devel
? sites/all/modules/drush
? sites/all/modules/imageapi
? sites/default/files
? sites/default/settings.php
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.156
diff -u -p -r1.156 file.inc
--- includes/file.inc	31 Jan 2009 16:50:56 -0000	1.156
+++ includes/file.inc	12 Feb 2009 19:42:44 -0000
@@ -802,6 +802,38 @@ function file_unmanaged_delete($path) {
 }
 
 /**
+ * Recursively delete all files and folders in the specified filepath.
+ *
+ * After the containing directory's files are deleted, the containing folder is
+ * also removed. Note that this only deletes visible files with write
+ * permission.
+ *
+ * @param $path
+ *   A string containing a file or directory path.
+ */
+function file_unmanaged_delete_recursive($path) {
+  if (is_file($path) || is_link($path)) {
+    unlink($path);
+  }
+  elseif (is_dir($path)) {
+    $dir = dir($path);
+    while (($entry = $dir->read()) !== false) {
+      if ($entry == '.' || $entry == '..') {
+        continue;
+      }
+      $entry_path = $path .'/'. $entry;
+      file_unmanaged_delete_recursive($entry_path);
+    }
+    rmdir($path);
+  }
+  else {
+    // Looks like they're trying to delete some other type of file that we
+    // can't handle like a socket.
+    watchdog('file', 'The file %path is not of a recognized type so it was not deleted.', array('%path' => $path), WATCHDOG_ERROR);
+  }
+}
+
+/**
  * Determine total disk space used by a single user or the whole filesystem.
  *
  * @param $uid
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.83
diff -u -p -r1.83 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	6 Feb 2009 00:30:36 -0000	1.83
+++ modules/simpletest/drupal_web_test_case.php	12 Feb 2009 19:42:44 -0000
@@ -902,7 +902,7 @@ class DrupalWebTestCase {
     global $db_prefix, $user;
     if (preg_match('/simpletest\d+/', $db_prefix)) {
       // Delete temporary files directory and reset files directory path.
-      simpletest_clean_temporary_directory(file_directory_path());
+      file_unmanaged_delete_recursive(file_directory_path());
       variable_set('file_directory_path', $this->originalFileDirectory);
 
       // Remove all prefixed tables (all the tables in the schema).
@@ -1999,7 +1999,7 @@ class DrupalWebTestCase {
     $match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
     return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser'));
   }
-  
+
   /**
    * TODO write documentation.
    * @param $type
@@ -2017,13 +2017,13 @@ class DrupalWebTestCase {
     );
     $field_definition += $settings;
     field_create_field($field_definition);
-    
+
     $field = field_read_field($field_name);
     $this->assertTrue($field, t('Created field @field_name of type @type.', array('@field_name' => $field_name, '@type' => $type)));
-    
+
     return $field;
   }
-  
+
   /**
    * TODO write documentation.
    * @param $field_name
@@ -2046,10 +2046,10 @@ class DrupalWebTestCase {
       ),
     );
     field_create_instance($instance_definition);
-    
+
     $instance = field_read_instance($field_name, $bundle);
     $this->assertTrue($instance, t('Created instance of field @field_name on bundle @bundle.', array('@field_name' => $field_name, '@bundle' => $bundle)));
-    
+
     return $instance;
   }
 }
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.35
diff -u -p -r1.35 simpletest.module
--- modules/simpletest/simpletest.module	25 Jan 2009 12:19:32 -0000	1.35
+++ modules/simpletest/simpletest.module	12 Feb 2009 19:42:44 -0000
@@ -550,7 +550,7 @@ function simpletest_clean_temporary_dire
   foreach ($files as $file) {
     $path = file_directory_path() . '/' . $file;
     if (is_dir($path) && preg_match('/^simpletest\d+/', $file)) {
-      simpletest_clean_temporary_directory($path);
+      file_unmanaged_delete_recursive($path);
       $count++;
     }
   }
@@ -564,27 +564,6 @@ function simpletest_clean_temporary_dire
 }
 
 /**
- * Remove all files from specified directory and then remove directory.
- *
- * @param string $path Directory path.
- */
-function simpletest_clean_temporary_directory($path) {
-  $files = scandir($path);
-  foreach ($files as $file) {
-    if ($file != '.' && $file != '..') {
-      $file_path = "$path/$file";
-      if (is_dir($file_path)) {
-        simpletest_clean_temporary_directory($file_path);
-      }
-      else {
-        file_unmanaged_delete($file_path);
-      }
-    }
-  }
-  rmdir($path);
-}
-
-/**
  * Clear the test results tables.
  */
 function simpletest_clean_results_table() {
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.22
diff -u -p -r1.22 file.test
--- modules/simpletest/tests/file.test	8 Feb 2009 15:06:30 -0000	1.22
+++ modules/simpletest/tests/file.test	12 Feb 2009 19:42:45 -0000
@@ -850,6 +850,83 @@ class FileUnmanagedDeleteTest extends Fi
 
 
 /**
+ * Deletion related tests.
+ */
+class FileUnmanagedDeleteRecursiveTest extends FileTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Unmanaged recursive file delete'),
+      'description' => t('Tests the unmanaged file delete recursive function.'),
+      'group' => t('File'),
+    );
+  }
+
+  /**
+   * Delete a normal file.
+   */
+  function testSingleFile() {
+    // Create a file for testing
+    $filepath = file_directory_path() . '/' . $this->randomName();
+    file_put_contents($filepath, '');
+
+    // Delete the file.
+    file_unmanaged_delete_recursive($filepath);
+    $this->assertFalse(file_exists($filepath), t('Test file has been deleted.'));
+  }
+
+  /**
+   * Try deleting an empty directory.
+   */
+  function testEmptyDirectory() {
+    // A directory to operate on.
+    $directory = $this->createDirectory();
+
+    // Delete the directory.
+    file_unmanaged_delete_recursive($directory);
+    $this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
+  }
+
+  /**
+   * Try deleting a directory with some files.
+   */
+  function testDirectory() {
+    // A directory to operate on.
+    $directory = $this->createDirectory();
+    $filepathA = $directory . '/A';
+    $filepathB = $directory . '/B';
+    file_put_contents($filepathA, '');
+    file_put_contents($filepathB, '');
+
+    // Delete the directory.
+    file_unmanaged_delete_recursive($directory);
+    $this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.'));
+    $this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.'));
+    $this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
+  }
+
+  /**
+   * Try deleting subdirectories with some files.
+   */
+  function testSubDirectory() {
+    // A directory to operate on.
+    $directory = $this->createDirectory();
+    $subdirectory = $this->createDirectory($directory . '/sub');
+    $filepathA = $directory . '/A';
+    $filepathB = $subdirectory . '/B';
+    file_put_contents($filepathA, '');
+    file_put_contents($filepathB, '');
+
+    // Delete the directory.
+    file_unmanaged_delete_recursive($directory);
+    $this->assertFalse(file_exists($filepathA), t('Test file A has been deleted.'));
+    $this->assertFalse(file_exists($filepathB), t('Test file B has been deleted.'));
+    $this->assertFalse(file_exists($subdirectory), t('Subdirectory has been deleted.'));
+    $this->assertFalse(file_exists($directory), t('Directory has been deleted.'));
+  }
+}
+
+
+/**
  * Unmanaged move related tests.
  */
 class FileUnmanagedMoveTest extends FileTestCase {
