unlink file if exists.
Return false if exists and unlink fails or if filePath is a dir.
@param string $filePath
@return bool
762866
public static function unlinkSafe(string $filePath) : bool
    {
        if (!FileHelper::fileExistsSafe($filePath)) {
            return false;
        }

        if (DirHelper::isDirSafe($filePath)) {
            return false;
        }

        return unlink($filePath);
    }
1205304
public function unlink($path)
    {
        $container = $this->getContainerFromContext($path);

        try {

            $path = $this->stripScheme($path);

            $parent = $container->nodeAt(dirname($path));

            $permissionHelper = $container->getPermissionHelper($parent);
            if (!$permissionHelper->isWritable()) {
                trigger_error(
                    sprintf('rm: %s: Permission denied', $path),
                    E_USER_WARNING
                );

                return false;
            }

            $container->remove($path = $this->stripScheme($path));
        } catch (NotFoundException $e) {
            trigger_error(
                sprintf('rm: %s: No such file or directory', $path),
                E_USER_WARNING
            );

            return false;
        } catch (\RuntimeException $e) {
            trigger_error(
                sprintf('rm: %s: is a directory', $path),
                E_USER_WARNING
            );

            return false;
        }

        return true;
    }
906985
public function deleteFile($filePath)
    {
        $this->throwIfOperationNotInBaseFolder($filePath);

        if (file_exists($filePath) && is_file($filePath)) {
            unlink($filePath);
        }
    }
851919
public function isFileAllowed($filePath)
    {
        $filePath = realpath($filePath);
        foreach ($this->allowedImageFolders as $key => $nextFolder) {
            if (0 === strpos($filePath, $nextFolder)) {
                return $key;
            }
        }

        return false;
    }
157896
public function unlink($path)
    {
        try {
            $path   = $this->getPath($path);
            if ($path->getRef() != 'HEAD') {
                throw new \Exception(sprintf(
                    'Cannot unlink a non-HEAD file [%s#%s]', $path->getFullPath(), $path->getRef()
                ));
            }
            if (!file_exists($path->getFullPath())) {
                throw new \Exception(sprintf('Path %s not found', $path->getFullPath()));
            }
            if (!is_file($path->getFullPath())) {
                throw new \Exception(sprintf('Path %s is not a file', $path->getFullPath()));
            }

            $repo   = $path->getRepository();

            $commitMsg      = $this->getContextOption('commitMsg', null);
            $author         = $this->getContextOption('author', null);

            $repo->removeFile($path->getLocalPath(), $commitMsg, false, false, $author);
            return true;
        } catch (\Exception $e) {
            trigger_error($e->getMessage(), E_USER_WARNING);
            return false;
        }
    }
1030723
public static function localDelete(string $path, string  $fileName) : bool
    {
        if (is_file($path . $fileName)) {
            unlink($path . $fileName);
        } else {
            return false;
        }
        return true;
    }
633985
public function unlink($url)
  {
    $partition = self::getPartition($url);
    $path = self::getRelativePath($url);

    return !!$partition->deleteFile($path);
  }
1261229
public function unlink($path)
    {
        if (false === self::cache()->get($path)) {
            return false;
        }

        self::cache()->delete($path);

        return true;
    }
1349403
private static function removeDirectoryRecursive($path) : bool
    {
        if ( !file_exists($path) ){
            return true;
        }

        $handle = opendir("$path");
        if ( $handle === FALSE ) {
            return false;
        }
        while ( false !== ($item = readdir($handle)) ) {
            if ($item != "." && $item != "..") {
                if (is_dir("$path/$item")) {
                    $res = self::removeDirectoryRecursive( "$path/$item" );
                    if (!$res){
                        return false;
                    }
                } else {
                    $res = @unlink( "$path/$item" );
                    if (!$res){
                        return false;
                    }
                }
            }
        }
        closedir( $handle );
        return @rmdir($path);
    }
1369716
public function deleteFile($filePath)
    {
        $filePath = realpath($filePath);

        // Check if it is an actual file and if it is writable.
        if (is_file($filePath) === true) {
            set_error_handler(
                function () {
                /* do nothing */
                }
            );
            // Make sure it is unlinkable.
            chmod($filePath, 0777);
            if (unlink($filePath) === true) {
                restore_error_handler();
                return;
            }

            // We have a permission problem here!
            $this->pool->messages->addMessage('fileserviceDelete', array($this->filterFilePath($filePath)));
            restore_error_handler();
        }
    }
1027738
private function removeDirectory(string $path): bool
    {
        $iterator = new DirectoryIterator($path);
        foreach ($iterator as $fileInfo) {
            if ($fileInfo->isDot() || !$fileInfo->isDir()) {
                continue;
            }
            $dirName = $fileInfo->getPathname();
            $this->removeDirectory($dirName);
        }

        $files = new FilesystemIterator($path);

        /** @var SplFileInfo $file */
        foreach ($files as $file) {
            $fileName = $file->getPathname();
            unlink($fileName);
        }

        return rmdir($path);
    }
884768
public function unlink($path) {
		$this->stream_open($path, 'r', [], $opath);
		$sql = $this->db->delete($this->table, 'WHERE id=?', true, $this->id);
		if ($sql['SUCCESS'] && $sql['AFFECTED_ROWS'] !== 0) return true;
		return false;
	}
1212465
public static function unlink($file)
    {
        // no errors should be thrown, return false instead.
        try {
            if (parent::unlink($file)) {
                return true;
            }
        } catch (\Exception $e) {}
        
        // try to force symlinks
        if (is_link($file)) {
            $sym = @readlink($file);
            if ($sym) {
                if (@unlink($file)) {
                    return true;
                }
            }
        }
        
        // try to use realpath
        if (realpath($file) && realpath($file) !== $file) {
            if (@unlink(realpath($file))) {
                return true;
            }
        }
        
        return false;
    }
665452
private function deleteFiles($dirPath)
    {
        foreach (glob($dirPath.DIRECTORY_SEPARATOR.'{*,.[!.]*,..?*}', GLOB_BRACE) as $content) {
            if (is_dir($content)) {
                $this->deleteFiles($content);
            } else {
                unlink($content);
            }
        }
        rmdir($dirPath);
    }
499874
public function removeDirectory(string $path): bool
	{
		foreach(new FilesystemIterator($path) as $item)
		{
			if($item->isDir())
			{
				$this->removeDirectory($item->getPathname());
			}
			else
			{
				unlink($item->getPathname());
			}
		}

		return rmdir($path);
	}
13607
public static function recursiveUnlink($dir) {
        $result = TRUE;

        if(is_dir($dir)) {
            foreach(scandir($dir) as $sub) {
                if(in_array($sub, ['.', '..'])) continue;
                $result &= self::recursiveUnlink("$dir/$sub");
            }

            $result &= rmdir($dir);
        }
        elseif(is_file($dir)) {
            $result &= unlink($dir);
        }
        else {
            $result = FALSE;
        }

        return (bool)$result;
    }
762225
public function unlink($path)
	{
		if(isset(static::$pointer_tree[$path_to]))
		{
			if(is_resource(static::$pointer_tree[$path_to]))
				fclose(static::$pointer_tree[$path_to]);
			
			unset(static::$pointer_tree[$path_to]);
		}
		
		return true;
	}