diff --git a/src/decompnet/project_migration.py b/src/decompnet/project_migration.py index 022be1653..2000fe398 100644 --- a/src/decompnet/project_migration.py +++ b/src/decompnet/project_migration.py @@ -33,7 +33,8 @@ def _file_hash(path): def durable(path): - with Path(path).open('rb') as handle:os.fsync(handle.fileno()) + # Windows FlushFileBuffers needs write access, even after SQLite has closed the snapshot. + with Path(path).open('r+b') as handle:os.fsync(handle.fileno()) if os.name != 'nt': descriptor = os.open(str(Path(path).parent),os.O_RDONLY) try:os.fsync(descriptor) diff --git a/tests/test_migration_durability.py b/tests/test_migration_durability.py new file mode 100644 index 000000000..5b23a4092 --- /dev/null +++ b/tests/test_migration_durability.py @@ -0,0 +1,10 @@ +"""Migration snapshots must flush on Windows as well as Unix.""" +from decompnet.project_migration import durable + + +def test_durable_snapshot_preserves_bytes(tmp_path): + snapshot = tmp_path / 'snapshot.db' + content = b'SQLite snapshot contents\x00\xff' + snapshot.write_bytes(content) + durable(snapshot) + assert snapshot.read_bytes() == content