Skip to content

Commit d9c3e64

Browse files
authored
Add endpoint to create a symlink on a directory (#681)
This will allow symlinks to be created to destinations from the frontend
1 parent e4b297a commit d9c3e64

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/murfey/server/api/file_io_frontend.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from logging import getLogger
2+
from pathlib import Path
23

34
from fastapi import APIRouter, Depends
5+
from pydantic import BaseModel
6+
from sqlmodel import Session, select
47

58
from murfey.server.api.auth import (
69
MurfeySessionIDFrontend as MurfeySessionID,
@@ -11,6 +14,7 @@
1114
process_gain as _process_gain,
1215
)
1316
from murfey.server.murfey_db import murfey_db
17+
from murfey.util.config import get_machine_config
1418

1519
logger = getLogger("murfey.server.api.file_io_frontend")
1620

@@ -28,3 +32,27 @@ async def process_gain(
2832
):
2933
result = await _process_gain(session_id, gain_reference_params, db)
3034
return result
35+
36+
37+
class SymlinkParameters(BaseModel):
38+
target: Path # these are the paths without the rsync basepath as that is what the frontend has access to
39+
symlink: Path
40+
override: bool = False
41+
42+
43+
@router.post("/sessions/{session_id}/symlink")
44+
async def create_symlink(
45+
session_id: MurfeySessionID, symlink_params: SymlinkParameters, db=murfey_db
46+
) -> str:
47+
murfey_session = db.exec(select(Session).where(Session.id == session_id)).one()
48+
instrument_name = murfey_session.instrument_name
49+
machine_config = get_machine_config(instrument_name=instrument_name)[
50+
instrument_name
51+
]
52+
symlink_full_path = machine_config.rsync_basepath / symlink_params.symlink
53+
if symlink_full_path.is_symlink() and symlink_params.override:
54+
symlink_full_path.unlink()
55+
if symlink_full_path.exists():
56+
return ""
57+
symlink_full_path.symlink_to(symlink_params.target)
58+
return str(symlink_params.symlink)

src/murfey/util/route_manifest.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ murfey.server.api.file_io_frontend.router:
477477
type: int
478478
methods:
479479
- POST
480+
- path: /file_io/frontend/sessions/{session_id}/symlink
481+
function: create_symlink
482+
path_params:
483+
- name: session_id
484+
type: int
485+
methods:
486+
- POST
480487
murfey.server.api.file_io_instrument.router:
481488
- path: /file_io/instrument/visits/{visit_name}/sessions/{session_id}/suggested_path
482489
function: suggest_path

0 commit comments

Comments
 (0)