Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d0b1b2d38 |
No files matched your search
@@ -1,5 +1,13 @@
|
||||
# Änderungsprotokoll
|
||||
|
||||
## 1.0.14 – 2026-09-29
|
||||
|
||||
### Behoben
|
||||
|
||||
- **Netzwerk- und Boot-Resilienz bei der Konfigurationsprüfung:** Beim Windows-Start wird die Aufgabenvalidierung von Quell- und Zielordnern nicht mehr durch noch nicht initialisierte Netzwerkverbindungen oder vorübergehend nicht erreichbare UNC-Pfade (`\\Server\Freigabe`) unterbrochen. Fehler bei der Pfadauflösung werden sicher abgefangen.
|
||||
- **Schutz vor fälschlichem Konfigurations-Reset:** Kurzzeitige Windows-Dateisperren (z. B. durch Hintergrund- oder Suchdienste beim Systemstart) führen nicht mehr zum irrtümlichen Umbenennen der Konfiguration in eine defekte Sicherung. Lesezugriffe auf die Konfigurationsdatei werden bei Sperren automatisch mehrfach wiederholt. Eine Sicherung als `config.defekt` erfolgt ausschließlich bei tatsächlichen Syntaxfehlern in der JSON-Datei.
|
||||
- **Fehlertolerantes Laden von Aufgaben:** Sollte eine einzelne gespeicherte Aufgabe ungültige Pfade oder Parameter enthalten, bleibt die Gesamtheit aller anderen Aufgaben unberührt. Die betroffene Aufgabe wird sicherheitsrelevanterweise deaktiviert in der Liste geladen, statt den Start zu blockieren oder andere Aufgaben zu verwerfen.
|
||||
|
||||
## 1.0.13 – 2026-09-28
|
||||
|
||||
### Behoben
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "syncvito"
|
||||
version = "1.0.13"
|
||||
version = "1.0.14"
|
||||
description = "Windows-Desktopwerkzeug für lokale und NAS-Synchronisation"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from contextlib import suppress
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -33,19 +35,47 @@ class ConfigStore:
|
||||
"""Lädt die Konfiguration; beschädigte Dateien werden gesichert."""
|
||||
if not self.path.exists():
|
||||
return AppConfig()
|
||||
|
||||
content: str | None = None
|
||||
last_io_exc: OSError | None = None
|
||||
for _ in range(5):
|
||||
try:
|
||||
raw = json.loads(self.path.read_text(encoding="utf-8"))
|
||||
content = self.path.read_text(encoding="utf-8")
|
||||
break
|
||||
except OSError as exc:
|
||||
last_io_exc = exc
|
||||
time.sleep(0.1)
|
||||
|
||||
if content is None:
|
||||
raise ConfigError(
|
||||
f"Konfigurationsdatei '{self.path.name}' konnte nicht gelesen werden: {last_io_exc}"
|
||||
) from last_io_exc
|
||||
|
||||
try:
|
||||
raw = json.loads(content)
|
||||
if not isinstance(raw, dict):
|
||||
raise ValueError("Das JSON-Wurzelelement ist kein Objekt.")
|
||||
return AppConfig.from_dict(raw)
|
||||
except (OSError, ValueError, TypeError, json.JSONDecodeError) as exc:
|
||||
except (ValueError, TypeError, json.JSONDecodeError) as exc:
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
recovery_path = self.path.with_name(f"config.defekt-{timestamp}.json")
|
||||
try:
|
||||
self.path.replace(recovery_path)
|
||||
except OSError:
|
||||
recovery_path = self.path
|
||||
raise ConfigError(f"Die Konfiguration war nicht lesbar. Sicherung: {recovery_path}") from exc
|
||||
raise ConfigError(
|
||||
f"Die Konfiguration war syntaktisch beschädigt ({exc}). Sicherung: {recovery_path}"
|
||||
) from exc
|
||||
|
||||
try:
|
||||
return AppConfig.from_dict(raw)
|
||||
except Exception as exc:
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
backup_path = self.path.with_name(f"config.bak-{timestamp}.json")
|
||||
with suppress(OSError):
|
||||
shutil.copy2(self.path, backup_path)
|
||||
raise ConfigError(
|
||||
f"Die Konfigurationsdaten konnten nicht verarbeitet werden ({exc}). Sicherungskopie: {backup_path}"
|
||||
) from exc
|
||||
|
||||
def save(self, config: AppConfig) -> None:
|
||||
"""Speichert die Konfiguration atomar und UTF-8-kodiert."""
|
||||
|
||||
+26
-4
@@ -82,8 +82,8 @@ class SyncTask:
|
||||
raise ValueError("Bitte einen Namen für die Aufgabe eingeben.")
|
||||
if not self.source.strip() or not self.target.strip():
|
||||
raise ValueError("Quell- und Zielordner müssen angegeben werden.")
|
||||
source = Path(self.source).expanduser().resolve(strict=False)
|
||||
target = Path(self.target).expanduser().resolve(strict=False)
|
||||
source = _safe_resolve(Path(self.source).expanduser())
|
||||
target = _safe_resolve(Path(self.target).expanduser())
|
||||
source_norm = os.path.normcase(str(source))
|
||||
target_norm = os.path.normcase(str(target))
|
||||
if source_norm == target_norm:
|
||||
@@ -123,7 +123,10 @@ class SyncTask:
|
||||
enabled=bool(data.get("enabled", True)),
|
||||
last_run=data.get("last_run"),
|
||||
)
|
||||
try:
|
||||
task.validate()
|
||||
except ValueError:
|
||||
task.enabled = False
|
||||
return task
|
||||
|
||||
|
||||
@@ -191,12 +194,28 @@ class AppConfig:
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> AppConfig:
|
||||
"""Erzeugt eine vollständige Konfiguration aus JSON-Daten."""
|
||||
tasks: list[SyncTask] = []
|
||||
for item in data.get("tasks", []):
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
try:
|
||||
tasks.append(SyncTask.from_dict(item))
|
||||
except Exception:
|
||||
continue
|
||||
return cls(
|
||||
tasks=[SyncTask.from_dict(item) for item in data.get("tasks", [])],
|
||||
tasks=tasks,
|
||||
settings=AppSettings.from_dict(data.get("settings", {})),
|
||||
)
|
||||
|
||||
|
||||
def _safe_resolve(path: Path) -> Path:
|
||||
"""Löst Pfade sicher auf; fängt Netzwerkfehler und unvollständige Pfade ab."""
|
||||
try:
|
||||
return path.resolve(strict=False)
|
||||
except OSError:
|
||||
return path.absolute()
|
||||
|
||||
|
||||
def _normalize_relative_path(value: str) -> str:
|
||||
normalized = value.replace("/", os.sep).replace("\\", os.sep).strip(os.sep)
|
||||
path = Path(normalized)
|
||||
@@ -206,8 +225,11 @@ def _normalize_relative_path(value: str) -> str:
|
||||
|
||||
|
||||
def _is_relative_to(path: Path, base: Path) -> bool:
|
||||
try:
|
||||
return path.is_relative_to(base)
|
||||
except (ValueError, OSError, AttributeError):
|
||||
try:
|
||||
path.relative_to(base)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
@@ -1,6 +1,9 @@
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from syncvito.config_store import ConfigStore
|
||||
import pytest
|
||||
|
||||
from syncvito.config_store import ConfigError, ConfigStore
|
||||
from syncvito.models import AppConfig, AppSettings, SyncDirection, SyncTask
|
||||
|
||||
|
||||
@@ -28,3 +31,64 @@ def test_config_roundtrip(tmp_path: Path) -> None:
|
||||
assert loaded.tasks[0].name == "Archiv"
|
||||
assert loaded.tasks[0].direction is SyncDirection.BIDIRECTIONAL
|
||||
assert loaded.tasks[0].selected_paths == ["Dokumente"]
|
||||
|
||||
|
||||
def test_config_corrupt_json_creates_backup(tmp_path: Path) -> None:
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text("{ unvollstaendiges json...", encoding="utf-8")
|
||||
|
||||
store = ConfigStore(path)
|
||||
with pytest.raises(ConfigError, match="syntaktisch beschädigt"):
|
||||
store.load()
|
||||
|
||||
defekt_files = list(tmp_path.glob("config.defekt-*.json"))
|
||||
assert len(defekt_files) == 1
|
||||
assert not path.exists()
|
||||
|
||||
|
||||
def test_config_read_locked_does_not_rename_file(tmp_path: Path) -> None:
|
||||
path = tmp_path / "config.json"
|
||||
path.write_text('{"schema_version": 1, "tasks": [], "settings": {}}', encoding="utf-8")
|
||||
|
||||
store = ConfigStore(path)
|
||||
with (
|
||||
patch.object(Path, "read_text", side_effect=PermissionError(13, "Permission denied")),
|
||||
pytest.raises(ConfigError, match="konnte nicht gelesen werden"),
|
||||
):
|
||||
store.load()
|
||||
|
||||
# Originaldatei darf bei Lese-/Sperrfehler NICHT umbenannt/gelöscht werden!
|
||||
assert path.exists()
|
||||
assert list(tmp_path.glob("config.defekt-*.json")) == []
|
||||
|
||||
|
||||
def test_config_load_with_invalid_task_keeps_task_disabled() -> None:
|
||||
data = {
|
||||
"schema_version": 1,
|
||||
"tasks": [
|
||||
{
|
||||
"name": "Ungültig",
|
||||
"source": "C:\\Ordner",
|
||||
"target": "C:\\Ordner", # Gleiche Quelle und Ziel -> ValueError bei validate()
|
||||
"interval_minutes": 30,
|
||||
}
|
||||
],
|
||||
"settings": {},
|
||||
}
|
||||
config = AppConfig.from_dict(data)
|
||||
assert len(config.tasks) == 1
|
||||
assert config.tasks[0].name == "Ungültig"
|
||||
assert config.tasks[0].enabled is False
|
||||
|
||||
|
||||
def test_sync_task_safe_resolve_network_oserror(tmp_path: Path) -> None:
|
||||
task = SyncTask(
|
||||
name="Netzwerk-Task",
|
||||
source=str(tmp_path / "lokal"),
|
||||
target=r"\\UnerreichbarerServer\Freigabe\Ordner",
|
||||
)
|
||||
with patch.object(Path, "resolve", side_effect=OSError("Network unreachable")):
|
||||
task.validate()
|
||||
|
||||
assert task.source == str((tmp_path / "lokal").resolve())
|
||||
assert r"\\UnerreichbarerServer\Freigabe\Ordner" in task.target
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.0.13
|
||||
1.0.14
|
||||
Reference in new issue
Block a user