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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Fixed
- **`manage_translations.py` Lade- und Rechtekante:** Eine nicht als UTF-8 lesbare `locales/translations.json` (z. B. UTF-16) endet jetzt mit der `[!]`-Meldung und Exit 1 statt mit Traceback; die atomare Schreibroutine übernimmt die bisherigen Dateirechte statt der `0600` von `NamedTemporaryFile`. Folge-Fix zu #8.

### Added
- **Multi-Target Plattform-Transfer, Windows Store Tier-2 Staging & Policy-10.1.3-Preflight (Stand 2026-11-14):**
- **Windows Store Tier-2 6-Sprachen-Staging (`TW-SV-01`):** `store_package.json`, `releases/windowsstore/store_settings.json` und `store_package/SQLite Viewer Pro/AppxManifest.xml` (`ProcessorArchitecture="x64"`, `Square310x310Logo="icons\icon_310x310.png"`, Paketversion `2.1.0.0` eingefroren synchron zu `APP_VERSION = "2.1.0"`) harmonisiert; fehlende `50x50` Store-Logo-Assets (`store_assets/StoreLogo.png`, `store_assets/Square50x50Logo.png`, `releases/windowsstore/StoreLogo.png`) ergänzt.
Expand Down
9 changes: 8 additions & 1 deletion manage_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import re
import os
import stat
import sys
import tempfile

Expand Down Expand Up @@ -140,6 +141,12 @@ def _atomic_write_json(file_path, data):
json.dump(data, f, indent=2, ensure_ascii=False)
f.flush()
os.fsync(f.fileno())
# NamedTemporaryFile legt unter POSIX 0600 an; bisherige Rechte beibehalten.
try:
mode = stat.S_IMODE(os.stat(file_path).st_mode)
except FileNotFoundError:
mode = 0o644
os.chmod(tmp_path, mode)
os.replace(tmp_path, file_path)
except Exception:
if tmp_path and os.path.exists(tmp_path):
Expand All @@ -158,7 +165,7 @@ def manage_translations(source_dir="."):
try:
with open(trans_file, "r", encoding="utf-8") as f:
translations = json.load(f)
except (json.JSONDecodeError, OSError) as exc:
except (json.JSONDecodeError, UnicodeDecodeError, OSError) as exc:
print(f"[!] Fehler beim Laden von {trans_file}: {exc}", file=sys.stderr)
return False
if not isinstance(translations, dict):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_manage_translations_cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""Regression tests for fail-closed behavior in manage_translations.py."""

import json
import os
import stat
import subprocess
import sys
from pathlib import Path

import pytest

import manage_translations as mt


Expand Down Expand Up @@ -71,3 +75,28 @@ def test_manage_translations_preserves_existing_and_adds_new_atomically(tmp_path
assert data["Speichern"]["en"] == "Save"
assert data["Datei öffnen"]["de"] == "Datei öffnen"
assert not list(locales_dir.glob(".translations.*.tmp"))


def test_manage_translations_aborts_on_non_utf8_file_without_overwriting(tmp_path: Path) -> None:
locales_dir = tmp_path / "locales"
locales_dir.mkdir(parents=True)
trans_file = locales_dir / "translations.json"
raw = '{"Übersetzung": {"de": "Übersetzung"}}'.encode("utf-16")
trans_file.write_bytes(raw)

ok = mt.manage_translations(str(tmp_path))

assert ok is False
assert trans_file.read_bytes() == raw


@pytest.mark.skipif(os.name == "nt", reason="POSIX-Dateirechte")
def test_atomic_write_preserves_existing_file_mode(tmp_path: Path) -> None:
trans_file = tmp_path / "translations.json"
trans_file.write_text("{}", encoding="utf-8")
os.chmod(trans_file, 0o644)

mt._atomic_write_json(str(trans_file), {"a": {"de": "a"}})

assert stat.S_IMODE(os.stat(trans_file).st_mode) == 0o644
assert json.loads(trans_file.read_text(encoding="utf-8")) == {"a": {"de": "a"}}