mirror of
https://github.com/allenai/olmocr.git
synced 2025-11-01 10:33:57 +00:00
Fixing one old bug to make update_static atomic
This commit is contained in:
parent
38dc5a2a0f
commit
4047258277
@ -120,8 +120,19 @@ def update_state(folder_path: str, filename: str, **kwargs):
|
||||
all_state[filename]["last_checked"] = datetime.datetime.now()
|
||||
|
||||
state_file = os.path.join(folder_path, UPLOAD_STATE_FILENAME)
|
||||
with open(state_file, "w") as f:
|
||||
return json.dump(all_state, f, default=_json_datetime_encoder)
|
||||
temp_file = state_file + '.tmp'
|
||||
|
||||
# Write to temporary file first
|
||||
with open(temp_file, "w") as f:
|
||||
json.dump(all_state, f, default=_json_datetime_encoder)
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
|
||||
# Atomic rename of temporary file to target file
|
||||
os.replace(temp_file, state_file)
|
||||
|
||||
return all_state
|
||||
|
||||
|
||||
def get_total_space_usage():
|
||||
return sum(file.bytes for file in client.files.list())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user