function FileStorage::unlink

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::unlink()
  2. 10 core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::unlink()
  3. 11.x core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::unlink()

Deletes files and/or directories in the specified path.

If the specified path is a directory the method will call itself recursively to process the contents. Once the contents have been removed the directory will also be removed.

Parameters

string $path: A string containing either a file or directory path.

Return value

bool TRUE for success or if path does not exist, FALSE in the event of an error.

4 calls to FileStorage::unlink()
FileStorage::delete in core/lib/Drupal/Component/PhpStorage/FileStorage.php
Deletes PHP code from storage.
FileStorage::deleteAll in core/lib/Drupal/Component/PhpStorage/FileStorage.php
Removes all files in this bin.
MTimeProtectedFastFileStorage::delete in core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php
Deletes PHP code from storage.
MTimeProtectedFastFileStorage::garbageCollection in core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php
Performs garbage collection on the storage.

File

core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 175

Class

FileStorage
Stores the code as regular PHP files.

Namespace

Drupal\Component\PhpStorage

Code

protected function unlink($path) {
    if (file_exists($path)) {
        if (is_dir($path)) {
            // Ensure the folder is writable.
            @chmod($path, 0777);
            foreach (new \DirectoryIterator($path) as $fileinfo) {
                if (!$fileinfo->isDot()) {
                    $this->unlink($fileinfo->getPathName());
                }
            }
            return @rmdir($path);
        }
        // Windows needs the file to be writable.
        @chmod($path, 0700);
        return @unlink($path);
    }
    // If there's nothing to delete return TRUE anyway.
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.