Fix no permission
This commit is contained in:
@@ -149,13 +149,20 @@ def month_add(year: int, month: int, delta: int) -> tuple[int, int]:
|
||||
m = (m % 12) + 1
|
||||
return y, m
|
||||
|
||||
def atomic_write(path: str, content: str):
|
||||
def atomic_write(path: str, content: str, mode: int = 0o644):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
fd, tmp_path = tempfile.mkstemp(prefix=os.path.basename(path) + ".", dir=os.path.dirname(path))
|
||||
|
||||
fd, tmp_path = tempfile.mkstemp(
|
||||
prefix=os.path.basename(path) + ".",
|
||||
dir=os.path.dirname(path),
|
||||
)
|
||||
try:
|
||||
with os.fdopen(fd, "w", encoding="utf-8", newline="") as f:
|
||||
f.write(content)
|
||||
|
||||
os.chmod(tmp_path, mode)
|
||||
os.replace(tmp_path, path)
|
||||
os.chmod(path, mode)
|
||||
finally:
|
||||
try:
|
||||
if os.path.exists(tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user