From 4c97eddfc3afced7f5149fbe3b79f193d14dd02a Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 22 Mar 2026 16:30:14 -0400 Subject: [PATCH] fix trunk check --- backend/handler/filesystem/sync_handler.py | 6 ++++-- backend/handler/sync/ssh_handler.py | 5 +++-- backend/tasks/sync_push_pull_task.py | 9 ++++++--- backend/tests/endpoints/roms/test_rom.py | 1 - backend/tests/endpoints/roms/test_upload.py | 1 - backend/tests/endpoints/test_sync.py | 3 --- .../handler/database/test_device_save_sync_handler.py | 2 +- backend/tests/handler/sync/test_comparison.py | 2 -- backend/tests/tasks/test_sync_push_pull.py | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/backend/handler/filesystem/sync_handler.py b/backend/handler/filesystem/sync_handler.py index 3aa4d9dbf..ba09ebcb2 100644 --- a/backend/handler/filesystem/sync_handler.py +++ b/backend/handler/filesystem/sync_handler.py @@ -105,6 +105,8 @@ class FSSyncHandler(FSHandler): # Validate the file is within our base path try: path.resolve().relative_to(self.base_path.resolve()) - except ValueError: - raise ValueError(f"Path {full_path} is outside the sync base directory") + except ValueError as e: + raise ValueError( + f"Path {full_path} is outside the sync base directory" + ) from e path.unlink() diff --git a/backend/handler/sync/ssh_handler.py b/backend/handler/sync/ssh_handler.py index 74bdabd56..8c493d1d6 100644 --- a/backend/handler/sync/ssh_handler.py +++ b/backend/handler/sync/ssh_handler.py @@ -20,6 +20,7 @@ from pathlib import Path from typing import Any import asyncssh +from anyio import open_file from config import SYNC_SSH_KEYS_PATH from logger.logger import log @@ -185,8 +186,8 @@ class SSHSyncHandler: # Compute hash hash_obj = hashlib.md5(usedforsecurity=False) - with open(local_path, "rb") as f: - while chunk := f.read(8192): + async with await open_file(local_path, "rb") as f: + while chunk := await f.read(8192): hash_obj.update(chunk) return local_path, hash_obj.hexdigest() diff --git a/backend/tasks/sync_push_pull_task.py b/backend/tasks/sync_push_pull_task.py index 88cc018ef..a59bf6b82 100644 --- a/backend/tasks/sync_push_pull_task.py +++ b/backend/tasks/sync_push_pull_task.py @@ -8,6 +8,9 @@ import os from datetime import datetime, timezone from typing import Any +from anyio import Path as AnyioPath +from anyio import open_file + from config import ENABLE_SYNC_PUSH_PULL, SYNC_PUSH_PULL_CRON from handler.database import ( db_device_handler, @@ -278,8 +281,8 @@ async def _process_remote_save( log.info( f"Push-pull: pulling {hl(remote_save.file_name)} from device {device.id}" ) - with open(local_path, "rb") as f: - file_data = f.read() + async with await open_file(local_path, "rb") as f: + file_data = await f.read() await fs_asset_handler.write_file( file=file_data, path=matched_save.file_path, @@ -324,7 +327,7 @@ async def _process_remote_save( return "conflict" finally: - if os.path.exists(local_path): + if await AnyioPath(local_path).exists(): os.unlink(local_path) return "skipped" diff --git a/backend/tests/endpoints/roms/test_rom.py b/backend/tests/endpoints/roms/test_rom.py index a976f3a14..d76762b25 100644 --- a/backend/tests/endpoints/roms/test_rom.py +++ b/backend/tests/endpoints/roms/test_rom.py @@ -1,7 +1,6 @@ import json from unittest.mock import AsyncMock, patch -import pytest from fastapi import status from fastapi.testclient import TestClient diff --git a/backend/tests/endpoints/roms/test_upload.py b/backend/tests/endpoints/roms/test_upload.py index dd2a243f4..e7cae1fb6 100644 --- a/backend/tests/endpoints/roms/test_upload.py +++ b/backend/tests/endpoints/roms/test_upload.py @@ -8,7 +8,6 @@ from fastapi.testclient import TestClient from endpoints.roms import upload as upload_endpoint from models.platform import Platform -from models.user import User @pytest.fixture diff --git a/backend/tests/endpoints/test_sync.py b/backend/tests/endpoints/test_sync.py index 8b80b782b..dc4ae8518 100644 --- a/backend/tests/endpoints/test_sync.py +++ b/backend/tests/endpoints/test_sync.py @@ -8,14 +8,11 @@ from fastapi import status from handler.database import ( db_device_handler, db_device_save_sync_handler, - db_save_handler, db_sync_session_handler, ) from models.assets import Save from models.device import Device, SyncMode -from models.platform import Platform from models.rom import Rom -from models.sync_session import SyncSession, SyncSessionStatus from models.user import User diff --git a/backend/tests/handler/database/test_device_save_sync_handler.py b/backend/tests/handler/database/test_device_save_sync_handler.py index 3fc395b2c..48ebc3a77 100644 --- a/backend/tests/handler/database/test_device_save_sync_handler.py +++ b/backend/tests/handler/database/test_device_save_sync_handler.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta, timezone +from datetime import datetime, timezone from handler.database import ( db_device_handler, diff --git a/backend/tests/handler/sync/test_comparison.py b/backend/tests/handler/sync/test_comparison.py index 7c470ac13..ece41358a 100644 --- a/backend/tests/handler/sync/test_comparison.py +++ b/backend/tests/handler/sync/test_comparison.py @@ -2,8 +2,6 @@ from datetime import datetime, timezone -import pytest - from handler.sync.comparison import SyncComparisonResult, compare_save_state diff --git a/backend/tests/tasks/test_sync_push_pull.py b/backend/tests/tasks/test_sync_push_pull.py index 09ecfa68c..1fc895a49 100644 --- a/backend/tests/tasks/test_sync_push_pull.py +++ b/backend/tests/tasks/test_sync_push_pull.py @@ -1,6 +1,6 @@ """Tests for SyncPushPullTask initialization and configuration.""" -from unittest.mock import MagicMock, patch +from unittest.mock import patch import pytest