delete symbolic link implementation (commonly known as "unlink()")

symbolic links on windows which link to directories need rmdir instead of unlink

@param string $path

@return bool
320000
private function unlinkImplementation($path)
    {
        if (defined('PHP_WINDOWS_VERSION_BUILD') && is_dir($path) && is_link($path)) {
            return rmdir($path);
        }

        return unlink($path);
    }
1116315
public static function removeDir($path)
    {
        if (is_file($path)) {
            unlink($path);
        } else {
            foreach (scandir($path) as $dir) {
                if ($dir === '.' || $dir === '..') {
                    continue;
                }

                static::removeDir($path.'/'.$dir);
            }

            rmdir($path);
        }
    }
378834
public function delete($path)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			if (@ftp_delete($this->conn, $path) === false)
			{
				if (@ftp_rmdir($this->conn, $path) === false)
				{
					Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

					return false;
				}
			}

			return true;
		}

		// Send delete file command and if that doesn't work, try to remove a directory
		if (!$this->_putCmd('DELE ' . $path, 250))
		{
			if (!$this->_putCmd('RMD ' . $path, 250))
			{
				Log::add(
					sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 250].  Path sent: %3$s', __METHOD__, $this->response, $path),
					Log::WARNING, 'jerror'
				);

				return false;
			}
		}

		return true;
	}
1303338
protected function _rrmdir( $path )
    {
        $i = new DirectoryIterator( $path );
        foreach( $i as $f )
        {
            if( $f->isFile() )
            {
                $this->warn( 'Permanently removed file ' . str_replace( base_path(), null, $f->getRealPath() ) );
                unlink( $f->getRealPath() );
            }
            else if( !$f->isDot() && $f->isDir() )
            {
                $this->_rrmdir( $f->getRealPath() );
            }
        }
        $this->warn( 'Permanently removed directory' . str_replace( base_path(), null, $path ) );
        rmdir( $path );
    }
1118116
public function removeDir($path)
    {
        if ($path == 'packages' or $path == '/') {
            return false;
        }

        $files = array_diff(scandir($path), ['.', '..']);
        foreach ($files as $file) {
            if (is_dir("$path/$file")) {
                $this->removeDir("$path/$file");
            } else {
                @chmod("$path/$file", 0777);
                @unlink("$path/$file");
            }

        }
        return rmdir($path);
    }
1174610
private function unlink($path)
    {
        if (!@$this->unlinkImplementation($path)) {
            // retry after a bit on windows since it tends to be touchy with mass removals
            if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@$this->unlinkImplementation($path))) {
                $error = error_get_last();
                $message = 'Could not delete '.$path.': '.@$error['message'];
                if (defined('PHP_WINDOWS_VERSION_BUILD')) {
                    $message .= "\nThis can be due to an antivirus or the Windows Search Indexer locking the file while they are analyzed";
                }

                throw new \RuntimeException($message);
            }
        }

        return true;
    }
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;
	}
857573
public static function deleteFolder($path) 
	{
		if(file_exists($path)) {
			$fh = dir($path);
			//print_r($fh);
			while (false !== ($files = $fh->read())) {
				/*
				echo $fh->path.'/'.$files."\n";
				chmod($fh->path.'/'.$files, 0755);
				if(@unlink($fh->path.'/'.$files))
					echo '1'."\n";
				else
					echo '0'."\n";
				*/
				@unlink($fh->path.'/'.$files);
			}
			$fh->close();
			@rmdir($path);

			return true;

		} else 
			return false;
	}
996967
public static function delete($path)
  {
    if (is_file($path)) {
      return unlink($path);
    }

    $files = array_diff(scandir($path), array('.', '..'));

    foreach ($files as $file) {
      (is_dir("$path/$file")) ? Filesystem::delete("$path/$file") : unlink("$path/$file");
    }

    return rmdir($path);
  }
742968
public function deleteOnce( string $path ): bool
	{
		try {
			if( ! @ unlink( $path ) ) throw new ErrorException;
		}
		catch( ErrorException $e )
		{
			return false;
		}

		return true;
	}
1352613
public function delete($path)
    {
        $location = $this->applyPathPrefix($path);

        try {
            $this->share->del($location);
        } catch (NotFoundException $e) {
            return false;
        } catch (InvalidTypeException $e) {
            return false;
        }

        return true;
    }
1241473
protected function _unlink($path) {
		return $this->query(sprintf('DELETE FROM %s WHERE id=%d AND mime!="directory" LIMIT 1', $this->tbf, $path)) && $this->db->affected_rows;
	}
1083814
public function deleteDir($path)
    {
        if (strpos($path, $this->directoryList->getPath('var')) === false) {
            return sprintf("Failed to delete directory - '%s'", $path);
        }

        $classFunc = [__CLASS__, __FUNCTION__];
        return is_file($path)
            ?
            @unlink($path)
            :
            array_map($classFunc, glob($path . '/*')) == @rmdir($path);
    }
653924
public function delete($path)
    {
        $path = realpath($path);
        if (strpos($path, $this->getDefaultPath()) === 0) {
            if (is_dir($path)) {
                foreach (glob($path . '/*') as $file) {
                    $this->delete($path);
                }
                return @rmdir($path);
            } else {
                return @unlink($path);
            }
        } else {
            throw new \InvalidArgumentException("Path not allowed '$path'");
        }
    }
1097420
public static function removeDirectory($path) {
        if (is_dir($path))
            $dir = opendir($path);
        if (!$dir)
            return false;
        while ($file = readdir($dir))
            if (!self::isDot($file)) {
	            if (!is_dir("$path/$file"))
                    unlink("$path/$file");
	            else
                    self::removeDirectory("$path/$file");
            }
        closedir($dir);
        rmdir($path);
        return true;
    }
1188128
public function delete($path)
    {
        $paths = is_array($path) ? $path : func_get_args();

        $success = true;

        foreach ($paths as $path) {

            if ($this->isDirectory($path)) {
                $success = $this->laravelFS->deleteDirectory($path);
                continue;
            }
            $success = $this->laravelFS->delete($path);

        }

        return $success;
    }
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;
	}