mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-10 14:44:18 +00:00
add explicit error when FSYNC is not supported on filesystem
This commit is contained in:
parent
5225c17073
commit
fbd9a7caa6
1 changed files with 10 additions and 5 deletions
|
@ -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'
|
mode = 'wb+' if isinstance(contents, bytes) else 'w'
|
||||||
|
|
||||||
# print('\n> Atomic Write:', mode, path, len(contents), f'overwrite={overwrite}')
|
# print('\n> Atomic Write:', mode, path, len(contents), f'overwrite={overwrite}')
|
||||||
|
try:
|
||||||
with lib_atomic_write(path, mode=mode, overwrite=overwrite) as f:
|
with lib_atomic_write(path, mode=mode, overwrite=overwrite) as f:
|
||||||
if isinstance(contents, dict):
|
if isinstance(contents, dict):
|
||||||
dump(contents, f, indent=4, sort_keys=True, cls=ExtendedEncoder)
|
dump(contents, f, indent=4, sort_keys=True, cls=ExtendedEncoder)
|
||||||
elif isinstance(contents, (bytes, str)):
|
elif isinstance(contents, (bytes, str)):
|
||||||
f.write(contents)
|
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))
|
os.chmod(path, int(OUTPUT_PERMISSIONS, base=8))
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
|
|
Loading…
Reference in a new issue