Aggiorna coda dopo ogni file copiato
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
from bakrest.backup import (
|
||||
_build_robocopy_command,
|
||||
_build_rsync_command,
|
||||
_robocopy_destination_dir,
|
||||
_run_robocopy,
|
||||
_split_existing_files,
|
||||
)
|
||||
from bakrest.config import parse_config
|
||||
from bakrest.registry import ChangeEvent
|
||||
from bakrest.registry import ChangeEvent, ChangeRegistry
|
||||
|
||||
|
||||
def test_split_existing_files_ignores_deleted(tmp_path: Path) -> None:
|
||||
@@ -95,3 +97,78 @@ def test_build_robocopy_command_preserves_path_under_include_root(tmp_path: Path
|
||||
assert command[3] == "image.psd"
|
||||
assert "/MIR" not in command
|
||||
assert "/PURGE" not in command
|
||||
|
||||
|
||||
def test_robocopy_marks_each_file_copied_after_all_destinations(
|
||||
tmp_path: Path,
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
source = tmp_path / "Lavori"
|
||||
source.mkdir()
|
||||
first = source / "a.docx"
|
||||
second = source / "b.docx"
|
||||
first.write_text("a", encoding="utf-8")
|
||||
second.write_text("b", encoding="utf-8")
|
||||
config = parse_config(
|
||||
{
|
||||
"watch": {
|
||||
"include_dirs": [str(source)],
|
||||
"include_extensions": [".docx"],
|
||||
"exclude_dirs": [],
|
||||
"exclude_patterns": [],
|
||||
},
|
||||
"backup": {
|
||||
"engine": "robocopy",
|
||||
"robocopy_path": "robocopy",
|
||||
"remote_destinations": ["\\\\server\\Backup1", "\\\\server\\Backup2"],
|
||||
"server_check": {"type": "tcp", "port": 445, "interval_seconds": 1800, "timeout_seconds": 1},
|
||||
},
|
||||
"storage": {
|
||||
"change_registry": str(tmp_path / "changes.sqlite"),
|
||||
"logs_dir": str(tmp_path / "logs"),
|
||||
"status_file": str(tmp_path / "status.json"),
|
||||
},
|
||||
"stability": {
|
||||
"min_age_seconds": 0,
|
||||
"unchanged_check_interval_seconds": 0,
|
||||
"unchanged_checks_required": 0,
|
||||
},
|
||||
},
|
||||
tmp_path / "config.toml",
|
||||
)
|
||||
registry = ChangeRegistry(config.storage.change_registry)
|
||||
events = [
|
||||
ChangeEvent(path=str(first), event_type="modified"),
|
||||
ChangeEvent(path=str(second), event_type="modified"),
|
||||
]
|
||||
for event in events:
|
||||
registry.record(event)
|
||||
|
||||
pending_counts_after_commands: list[int] = []
|
||||
|
||||
def fake_run(command, capture_output, text, check):
|
||||
pending_counts_after_commands.append(registry.pending_count())
|
||||
return subprocess.CompletedProcess(command, 0, stdout="", stderr="")
|
||||
|
||||
monkeypatch.setattr("bakrest.backup.subprocess.run", fake_run)
|
||||
|
||||
result = _run_robocopy(config, events, _NullLogger(), registry)
|
||||
|
||||
assert result.success
|
||||
assert result.copied_count == 2
|
||||
assert registry.pending_count() == 0
|
||||
assert pending_counts_after_commands == [2, 2, 1, 1]
|
||||
|
||||
|
||||
class _NullLogger:
|
||||
def info(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def warning(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def error(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
def exception(self, *args, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user