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
4 changes: 3 additions & 1 deletion loopx/control_plane/coordination/sqlite_backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export async function snapshotSqliteDatabase(source: string, destination: string
throw new Error("SQLite backup integrity check failed");
}
} finally { copy.close(); }
const handle = await open(destination, "r");
// Windows flush (FlushFileBuffers) requires write access; the snapshot bytes
// are already complete, so update mode only permits the durability sync.
const handle = await open(destination, "r+");
try { await handle.sync(); } finally { await handle.close(); }
return info;
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion loopx/state_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ def execute_state_backup_plan(payload: dict[str, Any]) -> dict[str, Any]:
staged_manifest.write_text(json.dumps(updated, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
for path in (staged_archive, staged_manifest):
path.chmod(0o600)
with path.open("rb") as handle:
# Windows requires write access for fsync; update mode only permits
# the durability flush.
with path.open("rb+") as handle:
os.fsync(handle.fileno())
os.replace(staged_archive, archive_path)
os.replace(staged_manifest, manifest_path)
Expand Down
3 changes: 2 additions & 1 deletion tests/control_plane_ts/sqlite_backup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ test("online backup preserves committed metadata, schema and blobs, excluding an
} finally { copy.close(); }
writer.exec("ROLLBACK");
assert.equal(writer.prepare("SELECT metadata FROM facts").get()?.metadata, metadata);
assert.equal((await stat(target)).mode & 0o777, 0o600);
// Windows stat reports 0o666 for every writable file and has no owner-only mode.
if (process.platform !== "win32") assert.equal((await stat(target)).mode & 0o777, 0o600);
} finally { writer.close(); }
});

Expand Down
6 changes: 4 additions & 2 deletions tests/test_state_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ def test_duplicate_targets_reuse_snapshot_and_preserve_ordinary_files(tmp_path):
assert (restored / "runtime-root/database-link").is_symlink()
assert "runtime-root/notes-wal" in names
assert (restored / "runtime-root/not-a-database.sqlite").read_text() == "ordinary text"
assert (Path(payload["archive_path"]).stat().st_mode & 0o777) == 0o600
assert (Path(payload["manifest_path"]).stat().st_mode & 0o777) == 0o600
if sys.platform != "win32":
# Windows stat reports 0o666 for every writable file and has no owner-only mode.
assert (Path(payload["archive_path"]).stat().st_mode & 0o777) == 0o600
assert (Path(payload["manifest_path"]).stat().st_mode & 0o777) == 0o600


def test_backup_does_not_walk_or_archive_junction_targets(tmp_path, monkeypatch):
Expand Down
Loading