Archive the raw transcript by content hash with its verdict, and stop on a failed archive
This commit is contained in:
@@ -11,12 +11,16 @@ def make_private(folder):
|
||||
|
||||
|
||||
def replace_json(path, data, **dump):
|
||||
return replace_file(path, json.dumps(data, **dump).encode())
|
||||
|
||||
|
||||
def replace_file(path, data):
|
||||
staged = f"{path}.{os.getpid()}"
|
||||
try:
|
||||
mode = os.stat(path).st_mode & 0o7777 if os.path.exists(path) else 0o600
|
||||
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "w", encoding="utf-8") as handle:
|
||||
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "wb") as handle:
|
||||
os.fchmod(handle.fileno(), mode)
|
||||
json.dump(data, handle, **dump)
|
||||
handle.write(data)
|
||||
os.replace(staged, path)
|
||||
except OSError as failure:
|
||||
if os.path.exists(staged):
|
||||
|
||||
Reference in New Issue
Block a user