From 98f8481146356fa1ea01f9e907e8a8d1ce7a57dd Mon Sep 17 00:00:00 2001 From: Daniel Hatton Date: Tue, 14 Oct 2025 17:50:53 +0100 Subject: [PATCH 1/2] add endpoint to create a symlink on a directory --- src/murfey/server/api/file_io_frontend.py | 29 +++++++++++++++++++++++ src/murfey/util/route_manifest.yaml | 7 ++++++ 2 files changed, 36 insertions(+) diff --git a/src/murfey/server/api/file_io_frontend.py b/src/murfey/server/api/file_io_frontend.py index 0356859b3..e0c9d5df6 100644 --- a/src/murfey/server/api/file_io_frontend.py +++ b/src/murfey/server/api/file_io_frontend.py @@ -1,6 +1,9 @@ from logging import getLogger +from pathlib import Path from fastapi import APIRouter, Depends +from pydantic import BaseModel +from sqlmodel import Session, select from murfey.server.api.auth import ( MurfeySessionIDFrontend as MurfeySessionID, @@ -11,6 +14,7 @@ process_gain as _process_gain, ) from murfey.server.murfey_db import murfey_db +from murfey.util.config import get_machine_config logger = getLogger("murfey.server.api.file_io_frontend") @@ -28,3 +32,28 @@ async def process_gain( ): result = await _process_gain(session_id, gain_reference_params, db) return result + + +class SymlinkParameters(BaseModel): + target: Path # these are the paths without the rsync basepath as that is what the frontend has access to + symlink: Path + override: bool = False + + +@router.post("/sessions/{session_id}/symlink") +async def create_symlink( + session_id: MurfeySessionID, symlink_params: SymlinkParameters, db=murfey_db +) -> str: + murfey_session = db.exec(select(Session).where(Session.id == session_id)).one() + instrument_name = murfey_session.instrument_name + machine_config = get_machine_config(instrument_name=instrument_name)[ + instrument_name + ] + symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink + if symlink_full_path.is_symlink(): + if symlink_params.override: + symlink_full_path.unlink() + elif symlink_full_path.exists(): + return "" + symlink_full_path.symlink_to(symlink_params.target) + return str(symlink_params.symlink) diff --git a/src/murfey/util/route_manifest.yaml b/src/murfey/util/route_manifest.yaml index 409d9589f..1c998a336 100644 --- a/src/murfey/util/route_manifest.yaml +++ b/src/murfey/util/route_manifest.yaml @@ -477,6 +477,13 @@ murfey.server.api.file_io_frontend.router: type: int methods: - POST + - path: /file_io/frontend/sessions/{session_id}/symlink + function: create_symlink + path_params: + - name: session_id + type: int + methods: + - POST murfey.server.api.file_io_instrument.router: - path: /file_io/instrument/visits/{visit_name}/sessions/{session_id}/suggested_path function: suggest_path From 26dfdee6f86210d499c95d424be4d6ee6de1f1ae Mon Sep 17 00:00:00 2001 From: Daniel Hatton Date: Fri, 17 Oct 2025 10:27:36 +0100 Subject: [PATCH 2/2] logic fix for override False but symlink already exists --- src/murfey/server/api/file_io_frontend.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/murfey/server/api/file_io_frontend.py b/src/murfey/server/api/file_io_frontend.py index e0c9d5df6..cc9e06f28 100644 --- a/src/murfey/server/api/file_io_frontend.py +++ b/src/murfey/server/api/file_io_frontend.py @@ -50,10 +50,9 @@ async def create_symlink( instrument_name ] symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink - if symlink_full_path.is_symlink(): - if symlink_params.override: - symlink_full_path.unlink() - elif symlink_full_path.exists(): + if symlink_full_path.is_symlink() and symlink_params.override: + symlink_full_path.unlink() + if symlink_full_path.exists(): return "" symlink_full_path.symlink_to(symlink_params.target) return str(symlink_params.symlink)