def _ensure_cache_dir_and_supporting_files(self) -> None:
        """Create the cache dir and its supporting files."""
        if self._cachedir.is_dir():
            return

        self._cachedir.parent.mkdir(parents=True, exist_ok=True)
        with tempfile.TemporaryDirectory(
            prefix="pytest-cache-files-",
            dir=self._cachedir.parent,
        ) as newpath:
            path = Path(newpath)

            # Reset permissions to the default, see #12308.
            # Note: there's no way to get the current umask atomically, eek.
            umask = os.umask(0o022)
            os.umask(umask)
            path.chmod(0o777 - umask)

            with open(path.joinpath("README.md"), "x", encoding="UTF-8") as f:
                f.write(README_CONTENT)
            with open(path.joinpath(".gitignore"), "x", encoding="UTF-8") as f:
                f.write("# Created by pytest automatically.\n*\n")
            with open(path.joinpath("CACHEDIR.TAG"), "xb") as f:
                f.write(CACHEDIR_TAG_CONTENT)

            try:
                path.rename(self._cachedir)
            except OSError as e:
                # If 2 concurrent pytests both race to the rename, the loser
                # gets "Directory not empty" from the rename. In this case,
                # everything is handled so just continue (while letting the
                # temporary directory be cleaned up).
                # On Windows, the error is a FileExistsError which translates to EEXIST.
                if e.errno not in (errno.ENOTEMPTY, errno.EEXIST):
                    raise
            else:
                # Create a directory in place of the one we just moved so that
                # `TemporaryDirectory`'s cleanup doesn't complain.
                #
                # TODO: pass ignore_cleanup_errors=True when we no longer support python < 3.10.
                # See https://github.com/python/cpython/issues/74168. Note that passing
                # delete=False would do the wrong thing in case of errors and isn't supported
                # until python 3.12.
                path.mkdir()
Create the cache dir and its supporting files.
src/_pytest/cacheprovider.py