Fix save on Docker bind-mount: write in-place instead of atomic rename
os.replace (rename) changes the inode which Docker bind-mounts prohibit (EBUSY). Write directly to the file instead; a single-process writer with RLock is safe without atomic rename. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c53e58baf1
commit
6c2c07430a
@ -1,6 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import threading
|
||||
from typing import Optional
|
||||
|
||||
@ -120,13 +118,5 @@ class Config():
|
||||
|
||||
def __save(self) -> None:
|
||||
with self.__lock:
|
||||
directory = os.path.dirname(os.path.abspath(self.__filename))
|
||||
fd, tmp_path = tempfile.mkstemp(dir=directory, suffix='.tmp')
|
||||
try:
|
||||
with os.fdopen(fd, 'w') as f:
|
||||
json.dump(self.__config, f, ensure_ascii=False, indent=4)
|
||||
os.replace(tmp_path, self.__filename)
|
||||
except Exception:
|
||||
if os.path.exists(tmp_path):
|
||||
os.remove(tmp_path)
|
||||
raise
|
||||
with open(self.__filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.__config, f, ensure_ascii=False, indent=4)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user