function unish_file_delete_recursive

8.0.x bootstrap.inc unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
6.x drush_testcase.inc unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
7.x bootstrap.inc unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
4.x drush_testcase.inc unish_file_delete_recursive($dir)
5.x drush_testcase.inc unish_file_delete_recursive($dir)
master bootstrap.inc unish_file_delete_recursive($dir, $force = TRUE, $follow_symlinks = FALSE)

Deletes the specified file or directory and everything inside it.

Usually respects read-only files and folders. To do a forced delete use drush_delete_tmp_dir() or set the parameter $forced.

This is essentially a copy of drush_delete_dir().

@todo This sort of duplication isn't very DRY. This is bound to get out of sync with drush_delete_dir(), as in fact it already has before.

Parameters

string $dir: The file or directory to delete.

bool $force: Whether or not to try everything possible to delete the directory, even if it's read-only. Defaults to FALSE.

bool $follow_symlinks: Whether or not to delete symlinked files. Defaults to FALSE--simply unlinking symbolic links.

Return value

bool FALSE on failure, TRUE if everything was deleted.

See also

drush_delete_dir()

6 calls to unish_file_delete_recursive()
archiveDumpCase::testArchiveRestoreNoCore in tests/archiveDumpTest.php
Test archive-restore for a site archive (--no-core).
archiveDumpCase::unTar in tests/archiveDumpTest.php
Untar an archive and return the path to the untarred folder.
Drush_TestCase::setUpFreshSandBox in tests/drush_testcase.inc
Remove any pre-existing sandbox, then create a new one.
Drush_TestCase::tearDownAfterClass in tests/drush_testcase.inc
Runs after all tests in a class are run. Remove sandbox directory.
pmDownloadCase::testDestination in tests/pmDownloadTest.php

... See full list

File

tests/drush_testcase.inc, line 597
Initialize a sandboxed environment. Starts with call unish_init() at bottom.

Code

function unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE) {
  // Do not delete symlinked files, only unlink symbolic links
  if (is_link($dir) && !$follow_symlinks) {
    return unlink($dir);
  }
  // Allow to delete symlinks even if the target doesn't exist.
  if (!is_link($dir) && !file_exists($dir)) {
    return TRUE;
  }
  if (!is_dir($dir)) {
    if ($force) {
      // Force deletion of items with readonly flag.
      @chmod($dir, 0777);
    }
    return unlink($dir);
  }
  if (unish_delete_dir_contents($dir, $force) === FALSE) {
    return FALSE;
  }
  if ($force) {
    // Force deletion of items with readonly flag.
    @chmod($dir, 0777);
  }
  return rmdir($dir);
}