Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/datasets/utils/filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,15 @@ class WindowsFileLock(BaseFileLock):
windows systems.
"""

def __init__(self, lock_file, timeout=-1, max_filename_length=255):
super().__init__(lock_file, timeout=timeout, max_filename_length=max_filename_length)
self._lock_file = "\\\\?\\" + os.path.abspath(os.path.expanduser(os.path.expandvars(self._lock_file)))

def _acquire(self):
open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC

try:
fd = os.open(self._lock_file, open_mode)
except FileNotFoundError:
raise
except OSError:
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


def test_filelock(tmpdir):
lock1 = FileLock(tmpdir / "foo.lock")
lock2 = FileLock(tmpdir / "foo.lock")
lock1 = FileLock(str(tmpdir / "foo.lock"))
lock2 = FileLock(str(tmpdir / "foo.lock"))
timeout = 0.01
with lock1.acquire():
with pytest.raises(Timeout):
Expand All @@ -19,7 +19,7 @@ def test_filelock(tmpdir):

def test_long_filename(tmpdir):
filename = "a" * 1000 + ".lock"
lock1 = FileLock(tmpdir / filename)
lock1 = FileLock(str(tmpdir / filename))
assert lock1._lock_file.endswith(".lock")
assert not lock1._lock_file.endswith(filename)
assert len(os.path.basename(lock1._lock_file)) <= 255
Expand Down