use pathlib everywhere

This commit is contained in:
Jörg Thalheim
2024-09-02 18:25:17 +02:00
parent 9de48de991
commit 1fa0e72bea
28 changed files with 88 additions and 113 deletions

View File

@@ -10,11 +10,11 @@ from .jsonrpc import ClanJSONEncoder
@contextmanager
def locked_open(filename: str | Path, mode: str = "r") -> Generator:
def locked_open(filename: Path, mode: str = "r") -> Generator:
"""
This is a context manager that provides an advisory write lock on the file specified by `filename` when entering the context, and releases the lock when leaving the context. The lock is acquired using the `fcntl` module's `LOCK_EX` flag, which applies an exclusive write lock to the file.
"""
with open(filename, mode) as fd:
with filename.open(mode) as fd:
fcntl.flock(fd, fcntl.LOCK_EX)
yield fd
fcntl.flock(fd, fcntl.LOCK_UN)