You are here

function hackedProjectWebDownloader::remove_dir in Hacked! 8.2

Recursively delete all files and folders in the specified filepath, then delete the containing folder.

Note that this only deletes visible files with write permission.

Parameters

string $path: A filepath relative to file_directory_path.

File

src/hackedProjectWebDownloader.php, line 101

Class

hackedProjectWebDownloader
Base class for downloading remote versions of projects.

Namespace

Drupal\hacked

Code

function remove_dir($path) {
  if (is_file($path) || is_link($path)) {
    unlink($path);
  }
  elseif (is_dir($path)) {
    $d = dir($path);
    while (($entry = $d
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
        continue;
      }
      $entry_path = $path . '/' . $entry;
      $this
        ->remove_dir($entry_path);
    }
    $d
      ->close();
    rmdir($path);
  }
  else {
    $message = $this
      ->t('Unknown file type(%path) stat: %stat ', [
      '%path' => $path,
      '%stat' => print_r(stat($path), 1),
    ]);
    \Drupal::logger('hacked')
      ->error($message);
  }
}