mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-29 10:53:49 +08:00
mapd wrap
This commit is contained in:
@@ -75,16 +75,26 @@ class CorruptTileMonitor:
|
||||
def quarantine_offline_tile(filename: str) -> Path | None:
|
||||
tile_path = Path(filename)
|
||||
try:
|
||||
tile_path.relative_to(OFFLINE_ROOT)
|
||||
relative_path = tile_path.relative_to(OFFLINE_ROOT)
|
||||
except ValueError:
|
||||
cloudlog.warning(f"mapd_wrapper refusing to quarantine unexpected path: {filename}")
|
||||
return None
|
||||
|
||||
if not tile_path.exists():
|
||||
quarantine_path = tile_path if tile_path.is_file() else None
|
||||
if quarantine_path is None and len(relative_path.parts) >= 2:
|
||||
archive_path = OFFLINE_ROOT / relative_path.parts[0] / f"{relative_path.parts[1]}.tar.gz"
|
||||
if archive_path.is_file():
|
||||
quarantine_path = archive_path
|
||||
|
||||
if quarantine_path is None:
|
||||
return None
|
||||
|
||||
quarantined = tile_path.with_name(f"{tile_path.name}.corrupt.{int(time.time())}")
|
||||
tile_path.rename(quarantined)
|
||||
quarantined = quarantine_path.with_name(f"{quarantine_path.name}.corrupt.{int(time.time())}")
|
||||
try:
|
||||
quarantine_path.rename(quarantined)
|
||||
except OSError:
|
||||
cloudlog.exception(f"mapd_wrapper failed to quarantine offline data: {quarantine_path}")
|
||||
return None
|
||||
return quarantined
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_quarantine_offline_tile_renames_file(tmp_path, monkeypatch):
|
||||
tile.parent.mkdir(parents=True)
|
||||
tile.write_text("bad")
|
||||
|
||||
monkeypatch.setattr("openpilot.starpilot.navigation.mapd_wrapper.OFFLINE_ROOT", offline_root)
|
||||
monkeypatch.setitem(quarantine_offline_tile.__globals__, "OFFLINE_ROOT", offline_root)
|
||||
|
||||
quarantined = quarantine_offline_tile(tile.as_posix())
|
||||
|
||||
@@ -40,3 +40,20 @@ def test_quarantine_offline_tile_renames_file(tmp_path, monkeypatch):
|
||||
assert not tile.exists()
|
||||
assert Path(quarantined).exists()
|
||||
assert Path(quarantined).name.startswith(f"{tile.name}.corrupt.")
|
||||
|
||||
|
||||
def test_quarantine_offline_tile_renames_backing_archive(tmp_path, monkeypatch):
|
||||
offline_root = tmp_path / "offline"
|
||||
archive = offline_root / "34/-88.tar.gz"
|
||||
archive.parent.mkdir(parents=True)
|
||||
archive.write_text("bad archive")
|
||||
virtual_tile = offline_root / "34/-88/34.750000_-87.750000_35.000000_-87.500000"
|
||||
|
||||
monkeypatch.setitem(quarantine_offline_tile.__globals__, "OFFLINE_ROOT", offline_root)
|
||||
|
||||
quarantined = quarantine_offline_tile(virtual_tile.as_posix())
|
||||
|
||||
assert quarantined is not None
|
||||
assert not archive.exists()
|
||||
assert Path(quarantined).exists()
|
||||
assert Path(quarantined).name.startswith(f"{archive.name}.corrupt.")
|
||||
|
||||
Reference in New Issue
Block a user