fix: handle cross-drive paths in get_info_file on Windows

os.path.relpath raises ValueError when file_path and base_dir are on
different Windows drive letters (e.g. model on M: but default folder on
C:). Iterate all registered folder paths for the model type and use the
first one that shares a drive with the file, falling back to filename-
only when no candidate matches.

Fixes: ValueError: path is on mount 'M:', start on mount 'C:'
This commit is contained in:
marc.bate
2026-06-08 19:04:55 -05:00
parent 285c7a17b1
commit 0c5d787c4f
+19 -2
View File
@@ -54,12 +54,29 @@ def get_info_file(file_path: str, model_type: str, force=False):
""" Returns the path to the info file.
Saves JSON files with lora name in _power_preview folder inside the model_type folder.
"""
base_dir = folder_paths.get_folder_paths(model_type)[0]
# Find the base dir that actually contains file_path. On Windows, os.path.relpath raises
# ValueError when path and start are on different drive letters (e.g. C: vs M:), so we
# iterate all registered folders and skip cross-drive candidates.
base_dir = None
relative_path = None
for candidate in folder_paths.get_folder_paths(model_type):
try:
rel = os.path.relpath(file_path, candidate)
if not rel.startswith('..'):
base_dir = candidate
relative_path = rel
break
except ValueError:
continue
if base_dir is None:
# Fallback: no candidate shares a drive with file_path; use first dir and filename only.
base_dir = folder_paths.get_folder_paths(model_type)[0]
relative_path = os.path.basename(file_path)
# Create a mirrored folder structure in loras/_power_preview
power_preview_dir = os.path.join(base_dir, '_power_preview')
relative_path = os.path.relpath(file_path, base_dir)
# Get the filename without extension and change to .json
filename_without_ext = os.path.splitext(os.path.basename(relative_path))[0]
relative_dir = os.path.dirname(relative_path)