fix trunk check

This commit is contained in:
Georges-Antoine Assi
2026-03-22 16:30:14 -04:00
parent 7f7f7eb752
commit 4c97eddfc3
9 changed files with 15 additions and 16 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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"

View File

@@ -1,7 +1,6 @@
import json
from unittest.mock import AsyncMock, patch
import pytest
from fastapi import status
from fastapi.testclient import TestClient

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone
from handler.database import (
db_device_handler,

View File

@@ -2,8 +2,6 @@
from datetime import datetime, timezone
import pytest
from handler.sync.comparison import SyncComparisonResult, compare_save_state

View File

@@ -1,6 +1,6 @@
"""Tests for SyncPushPullTask initialization and configuration."""
from unittest.mock import MagicMock, patch
from unittest.mock import patch
import pytest