#8702·datasets

Windows: `load_dataset` fails with WinError 206 for moderately deep `cache_dir` because the lock filename duplicates the whole path

Author: 825pranavCreated Sep 27, 2026Updated Sep 27, 2026

Describe the bug

On Windows, load_dataset() fails with FileNotFoundError: [WinError 206] The filename or extension is too long for cache directories that are only moderately deep (~85+ characters, e.g. a OneDrive Documents folder), well before Windows' actual 260-character MAX_PATH limit would justify it.

Cause: the builder lock name flattens the entire absolute cache dir into the lock filename (Path(self._cache_dir).as_posix().replace("/", "_") + ".lock" in src/datasets/builder.py), which roughly doubles the total path length. The guard in src/datasets/utils/_filelock.py (FileLock.hash_filename_if_too_long) only shortens filenames longer than 255 chars and never considers the total path against MAX_PATH, so filelock fails to create the file. The vendored lock handled this before the switch to the filelock package in #6445 (long-path handling originally added in #2621).

Scope note: this fix restores load_dataset for cache dirs up to the point where the arrow shard paths themselves hit MAX_PATH (~110+ char cache dirs) — that deeper limit is the OS one and needs LongPathsEnabled (or \?\ handling) and is out of scope here. The point is that the lock file currently breaks at roughly half the depth everything else can handle.

Steps to reproduce the bug

python
import datasets, os, tempfile

base = tempfile.mkdtemp()
cache = os.path.join(base, "cache")
cache = cache + "x" * (95 - len(cache))   # 95-char cache dir; a OneDrive path easily reaches this
os.makedirs(cache)
csv = os.path.join(base, "mini.csv")
open(csv, "w").write("a,b\n1,2\n3,4\n")

datasets.load_dataset("csv", data_files=csv, split="train", cache_dir=cache)
# FileNotFoundError: [WinError 206] The filename or extension is too long.:
# '...\cache...\csv\default-...\0.0.0\_Users_..._cachexxxx_csv_default-..._0.0.0_....lock'

Expected behavior

hash_filename_if_too_long should also cap the lock filename so dirname + filename stays within 259 chars on Windows. With that change (3 lines), the repro above loads fine (rows=2) and tests/test_filelock.py passes. Happy to open a PR.

Environment info

  • datasets 5.0.2.dev0 (main @ a4ee9cf); Python 3.12.10; Windows 11 (LongPathsEnabled off, the default)