Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/decompnet/project_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_migration_durability.py
Original file line number Diff line number Diff line change
@@ -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
Loading