Skip to content

Commit e1fa429

Browse files
authored
Modified API endpoint that RsyncerInstance deletion requests are sent to; added log to capture when a deletion request fails on a specified RsyncerInstance (#578)
Passing paths in the URL to a FastAPI endpoint will cause the leading '/' in Unix-style paths to be removed. Passing the path as a properly quoted/escaped query component in the URL will prevent this from occurring.
1 parent 4243136 commit e1fa429

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/murfey/client/multigrid_control.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from functools import partial
88
from pathlib import Path
99
from typing import Dict, List, Optional
10-
from urllib.parse import urlparse
10+
from urllib.parse import quote, urlparse
1111

1212
import aiohttp
1313
import requests
@@ -189,9 +189,7 @@ def _start_rsyncer_multigrid(
189189

190190
def _rsyncer_stopped(self, source: Path, explicit_stop: bool = False):
191191
if explicit_stop:
192-
remove_url = (
193-
f"{self.murfey_url}/sessions/{self.session_id}/rsyncer/{str(source)}"
194-
)
192+
remove_url = f"{self.murfey_url}/sessions/{self.session_id}/rsyncer?source={quote(str(source), safe='')}"
195193
requests.delete(remove_url)
196194
else:
197195
stop_url = f"{self.murfey_url}/sessions/{self.session_id}/rsyncer_stopped"

src/murfey/server/api/__init__.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,22 @@ def register_rsyncer(session_id: int, rsyncer_info: RsyncerInfo, db=murfey_db):
296296
return rsyncer_info
297297

298298

299-
@router.delete("/sessions/{session_id}/rsyncer/{source:path}")
300-
def delete_rsyncer(session_id: int, source: str, db=murfey_db):
301-
rsync_instance = db.exec(
302-
select(RsyncInstance)
303-
.where(RsyncInstance.session_id == session_id)
304-
.where(RsyncInstance.source == source)
305-
).one()
306-
db.delete(rsync_instance)
307-
db.commit()
299+
@router.delete("/sessions/{session_id}/rsyncer")
300+
def delete_rsyncer(session_id: int, source: Path, db=murfey_db):
301+
try:
302+
rsync_instance = db.exec(
303+
select(RsyncInstance)
304+
.where(RsyncInstance.session_id == session_id)
305+
.where(RsyncInstance.source == str(source))
306+
).one()
307+
db.delete(rsync_instance)
308+
db.commit()
309+
except Exception:
310+
log.error(
311+
f"Failed to delete rsyncer for source directory {sanitise(str(source))!r} "
312+
f"in session {session_id}.",
313+
exc_info=True,
314+
)
308315

309316

310317
@router.post("/sessions/{session_id}/rsyncer_stopped")

0 commit comments

Comments
 (0)