diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/file.inc | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/includes/file.inc b/includes/file.inc index 05318add6..6c865eeaf 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -782,6 +782,7 @@ function file_delete($file, $force = FALSE) { * error. * * @see file_delete() + * @see file_unmanaged_delete_recursive() */ function file_unmanaged_delete($path) { if (is_dir($path)) { @@ -797,11 +798,48 @@ function file_unmanaged_delete($path) { watchdog('file', 'The file %path was not deleted, because it does not exist.', array('%path' => $path), WATCHDOG_NOTICE); return TRUE; } - // Catch all for everything else: sockets, symbolic links, etc. + // We cannot handle anything other than files and directories. Log an error + // for everything else (sockets, symbolic links, etc). + watchdog('file', 'The file %path is not of a recognized type so it was not deleted.', array('%path' => $path), WATCHDOG_ERROR); return FALSE; } /** + * Recursively delete all files and directories in the specified filepath. + * + * If the specified path is a directory then the function will call itself + * recursively to process the contents. Once the contents have been removed the + * directory will also be removed. + * + * If the specified path is a file then it will be passed to + * file_unmanaged_delete(). + * + * Note that this only deletes visible files with write permission. + * + * @param $path + * A string containing a file or directory path. + * @return + * TRUE for success or path does not exist, or FALSE in the event of an + * error. + * + * @see file_unmanaged_delete() + */ +function file_unmanaged_delete_recursive($path) { + if (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); + } + return rmdir($path); + } + return file_unmanaged_delete($path); +} + +/** * Determine total disk space used by a single user or the whole filesystem. * * @param $uid |