@@ -222,29 +222,34 @@ def convert_epoch_string_to_int(epoch_string):
222222
223223def 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
249254def import_metadata_row (metadata_object ):
250255 """
0 commit comments