From fbd9a7caa6c227a59c16028cd00b059d60cba0a7 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 10 Nov 2020 01:07:56 -0500 Subject: [PATCH] add explicit error when FSYNC is not supported on filesystem --- archivebox/system.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/archivebox/system.py b/archivebox/system.py index 1adcffc7..2caf58e1 100644 --- a/archivebox/system.py +++ b/archivebox/system.py @@ -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}') - 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) + 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