mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-12 12:32:11 -03:00
fix(paths): keep business paths forward-slashed on Windows
Four places produced the host's separator (or a mixed path) where the app's
business form is forward-slashed, so on Windows the value could not be compared
with the one the rest of the app stores:
* `ModelScanner._calculate_folder` matched `file_path.startswith(root)` as raw
strings, so every forward-slashed path resolved to the library root and a
moved model was filed under the root instead of its folder. It now compares
root identities and slices the relative part off.
* `normalize_relative_folder` ran `os.path.normpath`, and ntpath folds forward
slashes back to backslashes: every folder parameter (scoped scan, create,
rename, delete) came back host-spelled and mismatched the stored folders.
* `_format_model_name_for_comfyui` returned `os.path.relpath` unchanged, so the
checkpoint/unet nodes and the metadata node emitted `unet\base.safetensors`
on Windows -- a name no ComfyUI widget list matches.
* `resolve_centralized_dir_for_dir` passed a component that spans two
directories ("<library>/<component>") whole to `os.path.join`, leaving a mixed
path ("...\comfyui/loras-1a2b3c4d\sub") that no native path equals.
Also hands the rename re-key callback business paths, like every other absolute
path the move service returns.
This commit is contained in:
@@ -3094,12 +3094,28 @@ class ModelScanner:
|
||||
return await MetadataManager.create_default_metadata(file_path, self.model_class)
|
||||
|
||||
def _calculate_folder(self, file_path: str) -> str:
|
||||
"""Calculate the folder path for a model file"""
|
||||
"""Return the library-relative folder holding *file_path*.
|
||||
|
||||
The path arrives in whichever spelling its caller holds: ComfyUI's own
|
||||
(backslashes on Windows) or the forward-slashed business form used for
|
||||
cache entries. A raw ``startswith(root)`` matched neither the mixed nor
|
||||
the opposite spelling, so every forward-slashed path on Windows resolved
|
||||
to the root folder and a moved model was filed under the library root.
|
||||
Compare identities instead, then slice the relative part off.
|
||||
"""
|
||||
candidate = _root_identity(file_path)
|
||||
if not candidate:
|
||||
return ""
|
||||
for root in self.get_model_roots():
|
||||
if file_path.startswith(root):
|
||||
rel_path = os.path.relpath(file_path, root)
|
||||
return os.path.dirname(rel_path).replace(os.path.sep, '/')
|
||||
return ''
|
||||
identity = _root_identity(root)
|
||||
if not identity:
|
||||
continue
|
||||
if candidate == identity:
|
||||
return ""
|
||||
if candidate.startswith(f"{identity}/"):
|
||||
relative = candidate[len(identity) + 1:]
|
||||
return relative.rsplit("/", 1)[0] if "/" in relative else ""
|
||||
return ""
|
||||
|
||||
def adjust_metadata(self, metadata, file_path, root_path):
|
||||
"""Hook for subclasses: adjust metadata during scanning"""
|
||||
|
||||
Reference in New Issue
Block a user