Skip to content

Commit 58f0621

Browse files
committed
fixup! feat(backup): a staged backup is restored into a fresh root, or refused (#731, slice 4)
fix(backup): one audited write site in backup_stage (check unit, run 42990175181) write_new_file opened its own os.open/os.fdopen pair, a second storage primitive the ADR-1110 redaction-gate audit counts once. Both writers now go through _new_private_file, so the audited count stays exact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018kyZYrVXPdxGjW7GSfGfmC
1 parent d975f92 commit 58f0621

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎mcp_server/infrastructure/backup_stage.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import os
2727
import shutil
2828
from pathlib import Path, PurePosixPath
29-
from typing import Iterable
29+
from typing import BinaryIO, Iterable
3030

3131
from mcp_server.shared.private_paths import PRIVATE_DIR_MODE, PRIVATE_FILE_MODE
3232

@@ -40,6 +40,15 @@
4040
)
4141

4242

43+
def _new_private_file(path: Path) -> BinaryIO:
44+
"""Open the new ``0o600`` file ``path`` for writing, never through a link.
45+
46+
The one write site of this module, audited in
47+
``tests_py/architecture/test_storage_redaction_gate.py`` (ADR-1110).
48+
"""
49+
return os.fdopen(os.open(path, _CREATE, PRIVATE_FILE_MODE), "wb")
50+
51+
4352
class StagingError(OSError):
4453
"""The staging root cannot receive a backup."""
4554

@@ -86,16 +95,13 @@ def copy_files(
8695
continue
8796
raise
8897
target = private_dirs(staging, relative.parent.as_posix()) / relative.name
89-
with (
90-
source,
91-
os.fdopen(os.open(target, _CREATE, PRIVATE_FILE_MODE), "wb") as out,
92-
):
98+
with source, _new_private_file(target) as out:
9399
shutil.copyfileobj(source, out)
94100

95101

96102
def write_new_file(directory: Path, name: str, data: bytes) -> None:
97103
"""Write ``data`` to the new ``0o600`` file ``directory/name``, never over one."""
98-
with os.fdopen(os.open(directory / name, _CREATE, PRIVATE_FILE_MODE), "wb") as out:
104+
with _new_private_file(directory / name) as out:
99105
out.write(data)
100106

101107

0 commit comments

Comments
 (0)