add explicit error when FSYNC is not supported on filesystem

This commit is contained in:
Nick Sweeting 2020-11-10 01:07:56 -05:00 committed by GitHub
parent 5225c17073
commit fbd9a7caa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,11 +39,16 @@ def atomic_write(path: Union[Path, str], contents: Union[dict, str, bytes], over
mode = 'wb+' if isinstance(contents, bytes) else 'w'
# print('\n> Atomic Write:', mode, path, len(contents), f'overwrite={overwrite}')
try:
with lib_atomic_write(path, mode=mode, overwrite=overwrite) as f:
if isinstance(contents, dict):
dump(contents, f, indent=4, sort_keys=True, cls=ExtendedEncoder)
elif isinstance(contents, (bytes, str)):
f.write(contents)
except OSError as e:
print(f"[X] OSError: Failed to write {path} with fcntl.F_FULLFSYNC. ({e})")
print(" For data integrity, ArchiveBox requires a filesystem that supports atomic writes.")
print(" Some filesystems and network drives don't implement FSYNC, and require workarounds.")
os.chmod(path, int(OUTPUT_PERMISSIONS, base=8))
@enforce_types