plan_materialisiere: nur innerhalb der Kopie schreiben; absoluter Pfad oder .. ist ein Befund
Ein absoluter Pfad in einer Ueberschrift schlug unter Windows die Kopie (kopie / "D:/..."), und das Skript ersetzte die echte Datei mit Exit 0. Gemessen an einer Probe-Datei im Scratchpad, entdeckt beim Planen von Paket E9 der Trading Plattform (Tasks 725 und 726 aendern Vault-Werkzeuge). Neu: in_kopie() an allen drei Schreibstellen. Regressionsnachweis: drei Ausbruchsfaelle je Befund und Exit 2, Dateien draussen unveraendert; Gegenprobe mit E9 723 und 724 byte-gleich. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0126RDfXiECscXipzf67uypJ
This commit is contained in:
1 parent
3230cb69d4
commit
b07fb20ed1
2 files changed
+35
-3
No files matched your search
@@ -62,6 +62,23 @@ def bloecke(taskdatei: Path):
|
||||
i += 1
|
||||
|
||||
|
||||
def in_kopie(kopie: Path, ziel: str) -> Path | None:
|
||||
"""Der Zielpfad in der Kopie, oder None, wenn er aus ihr hinausfuehrt.
|
||||
|
||||
Nachbesserung 2026-10-11 (Paket E9 der Trading Plattform): Ein absoluter Pfad in einer
|
||||
Ueberschrift schlug unter Windows die Kopie (kopie / "D:/..." ist der absolute Pfad), und das
|
||||
Skript schrieb mit Exit 0 in die echte Datei; gemessen im Scratchpad an einer Probe-Datei.
|
||||
Seitdem ist ein Ziel ausserhalb der Kopie (absolut oder mit "..") ein Befund, und nichts wird
|
||||
geschrieben.
|
||||
"""
|
||||
pfad = (kopie / ziel).resolve()
|
||||
try:
|
||||
pfad.relative_to(kopie.resolve())
|
||||
except ValueError:
|
||||
return None
|
||||
return pfad
|
||||
|
||||
|
||||
LOESCHZIEL = re.compile(r"^- `(.+?)`\s*\((.*)\)\s*$")
|
||||
|
||||
|
||||
@@ -110,7 +127,12 @@ def main() -> int:
|
||||
print(f"BEFUND {name}:{block['zeile']}: wird-Block ohne Aus-Block oder ohne Zieldatei")
|
||||
befunde += 1
|
||||
continue
|
||||
pfad = kopie / ziel
|
||||
pfad = in_kopie(kopie, ziel)
|
||||
if pfad is None:
|
||||
print(f"BEFUND {name}:{block['zeile']}: Zieldatei {ziel} liegt ausserhalb der Kopie, nichts geschrieben")
|
||||
befunde += 1
|
||||
alt = None
|
||||
continue
|
||||
if not pfad.exists():
|
||||
print(f"BEFUND {name}:{block['zeile']}: Zieldatei {ziel} fehlt in der Kopie")
|
||||
befunde += 1
|
||||
@@ -129,14 +151,22 @@ def main() -> int:
|
||||
continue
|
||||
alt = None
|
||||
if ("Die ganze Datei ist neu" in marke or "vollständig ersetzt" in marke) and ziel is not None:
|
||||
pfad = kopie / ziel
|
||||
pfad = in_kopie(kopie, ziel)
|
||||
if pfad is None:
|
||||
print(f"BEFUND {name}:{block['zeile']}: Zieldatei {ziel} liegt ausserhalb der Kopie, nichts geschrieben")
|
||||
befunde += 1
|
||||
continue
|
||||
pfad.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(pfad, "w", encoding="utf-8", newline="\n") as strom:
|
||||
strom.write(block["text"].rstrip("\n") + "\n")
|
||||
zaehler["neu"] += 1
|
||||
continue
|
||||
if marke.startswith("Häng diesen Block ans Ende") and ziel is not None:
|
||||
pfad = kopie / ziel
|
||||
pfad = in_kopie(kopie, ziel)
|
||||
if pfad is None:
|
||||
print(f"BEFUND {name}:{block['zeile']}: Zieldatei {ziel} liegt ausserhalb der Kopie, nichts geschrieben")
|
||||
befunde += 1
|
||||
continue
|
||||
text = normal(pfad.read_text(encoding="utf-8"))
|
||||
with open(pfad, "w", encoding="utf-8", newline="\n") as strom:
|
||||
strom.write(text.rstrip("\n") + "\n" + block["text"].rstrip("\n") + "\n")
|
||||
|
||||
Reference in new issue
Block a user