19 lines
519 B
Python
19 lines
519 B
Python
"""简单的文件锁标记工具。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from os import PathLike
|
|
from pathlib import Path
|
|
|
|
|
|
def is_lock(file_path: str | PathLike[str]) -> bool:
|
|
"""判断指定的锁文件是否存在。"""
|
|
return Path(file_path).is_file()
|
|
|
|
|
|
def write_lockfile(file_path: str | PathLike[str]) -> None:
|
|
"""创建锁文件;父目录不存在时自动创建。"""
|
|
path = Path(file_path)
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text("LOCK", encoding="utf-8")
|