private function canRemoveSymlink($source, $target, $mode)
    {
        if (!file_exists($target)) {
            return false;
        }

        if (!is_link($target)
            || $this->filesystem->normalizePath($source) !== $this->filesystem->normalizePath(realpath($target))
        ) {
            if (self::INVALID_IGNORE === $mode) {
                return false;
            }

            if (self::INVALID_FAIL === $mode) {
                throw new \RuntimeException(
                    sprintf(
                        '"%s" is not a link to "%s" (expected "%s" but got "%s")',
                        $target,
                        $source,
                        $this->filesystem->normalizePath($source),
                        $this->filesystem->normalizePath(realpath($target))
                    )
                );
            }
        }

        return true;
    }