Repository: pypa/pip
File: src/pip/_internal/commands/cache.py (Python)

Code before:
            # Add the pattern to the log message
            no_matching_msg += f' for pattern "{args[0]}"'

        if not files:
            logger.warning(no_matching_msg)

        bytes_removed = 0
        for filename in files:
            bytes_removed += os.stat(filename).st_size
            os.unlink(filename)
            logger.verbose("Removed %s", filename)

        http_dirs = filesystem.subdirs_without_files(self._cache_dir(options, "http"))
        wheel_dirs = filesystem.subdirs_without_wheels(
            self._cache_dir(options, "wheels")
        )
        dirs = [*http_dirs, *wheel_dirs]

        for subdir in dirs:
            try:
                for file in subdir.iterdir():
                    file.unlink(missing_ok=True)
                subdir.rmdir()
            except FileNotFoundError:
                # If the file is already gone, that's fine.
                pass
            logger.verbose("Removed %s", subdir)

        # selfcheck.json is no longer used by pip.
        selfcheck_json = self._cache_dir(options, "selfcheck.json")
        if os.path.isfile(selfcheck_json):
            os.remove(selfcheck_json)
            logger.verbose("Removed legacy selfcheck.json file")

        logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed))
        logger.info("Directories removed: %s", len(dirs))

    def purge_cache(self, options: Values, args: list[str]) -> None:
        if args:
            raise CommandError("Too many arguments")

        return self.remove_cache_items(options, ["*"])

    def _cache_dir(self, options: Values, subdir: str) -> str:
        return os.path.join(options.cache_dir, subdir)

    def _find_http_files(self, options: Values) -> list[str]:
        old_http_dir = self._cache_dir(options, "http")
        new_http_dir = self._cache_dir(options, "http-v2")
        return filesystem.find_files(old_http_dir, "*") + filesystem.find_files(
            new_http_dir, "*"

Review comment (suggestion):
`file.unlink(missing_ok=True)` can't raise a FileNotFoundError. Is this a typo?

```suggestion
            except FileNotFoundError:
                # If the directory is already gone, that's fine.
                pass
```

Code after:
            # Add the pattern to the log message
            no_matching_msg += f' for pattern "{args[0]}"'

        if not files:
            logger.warning(no_matching_msg)

        bytes_removed = 0
        for filename in files:
            bytes_removed += os.stat(filename).st_size
            os.unlink(filename)
            logger.verbose("Removed %s", filename)

        http_dirs = filesystem.subdirs_without_files(self._cache_dir(options, "http"))
        wheel_dirs = filesystem.subdirs_without_wheels(
            self._cache_dir(options, "wheels")
        )
        dirs = [*http_dirs, *wheel_dirs]

        for subdir in dirs:
            try:
                for file in subdir.iterdir():
                    file.unlink(missing_ok=True)
                subdir.rmdir()
            except FileNotFoundError:
                # If the directory is already gone, that's fine.
                pass
            logger.verbose("Removed %s", subdir)

        # selfcheck.json is no longer used by pip.
        selfcheck_json = self._cache_dir(options, "selfcheck.json")
        if os.path.isfile(selfcheck_json):
            os.remove(selfcheck_json)
            logger.verbose("Removed legacy selfcheck.json file")

        logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed))
        logger.info("Directories removed: %s", len(dirs))

    def purge_cache(self, options: Values, args: list[str]) -> None:
        if args:
            raise CommandError("Too many arguments")

        return self.remove_cache_items(options, ["*"])

    def _cache_dir(self, options: Values, subdir: str) -> str:
        return os.path.join(options.cache_dir, subdir)

    def _find_http_files(self, options: Values) -> list[str]:
        old_http_dir = self._cache_dir(options, "http")
        new_http_dir = self._cache_dir(options, "http-v2")
        return filesystem.find_files(old_http_dir, "*") + filesystem.find_files(
            new_http_dir, "*"