Skip to content

Commit 3c74625

Browse files
committed
fix: Allow output path to be overriden and fix root path retrieval in form
1 parent 3df58fe commit 3c74625

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

laue_portal/database/db_utils.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,29 +222,34 @@ def convert_epoch_string_to_int(epoch_string):
222222

223223
def remove_root_path_prefix(file_path, root_path):
224224
"""
225-
Remove root_path prefix from a file path and any leading slash.
225+
Remove root_path prefix from a file path.
226+
227+
If the file_path starts with root_path, returns the relative path.
228+
If the file_path is an absolute path that doesn't start with root_path,
229+
returns it as-is (preserving the leading '/').
226230
227231
Args:
228232
file_path: The full file path
229233
root_path: The root path prefix to remove
230234
231235
Returns:
232-
str: The file path with root_path prefix removed
236+
str: The file path with root_path prefix removed (if present),
237+
or the original path if it doesn't start with root_path
233238
"""
234239
if not file_path:
235240
return ""
236241

237-
result_path = file_path
238-
239242
# Remove root_path from file_path if it starts with it
240243
if root_path and file_path.startswith(root_path):
241244
result_path = file_path[len(root_path):]
242-
243-
# Remove leading slash if present
244-
if result_path.startswith('/'):
245-
result_path = result_path[1:]
246-
247-
return result_path
245+
# Only remove leading slash if we actually stripped the root_path
246+
# This ensures we return a proper relative path
247+
if result_path.startswith('/'):
248+
result_path = result_path[1:]
249+
return result_path
250+
251+
# Path doesn't start with root_path - return as-is (could be absolute or already relative)
252+
return file_path
248253

249254
def import_metadata_row(metadata_object):
250255
"""

laue_portal/pages/create_peakindexing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,8 @@ def submit_parameters(n,
14141414
logger.error(f"Failed to format output folder '{current_output_folder}': {e}")
14151415
formatted_output_folder = current_output_folder # Fallback if formatting fails
14161416

1417-
full_output_folder = os.path.join(root_path, formatted_output_folder.lstrip('/'))
1417+
# Use resolve_path_with_root to allow absolute paths to override root_path
1418+
full_output_folder = resolve_path_with_root(formatted_output_folder, root_path)
14181419

14191420
# Create output directory if it doesn't exist
14201421
try:

0 commit comments

Comments
 (0)