fix: filter local hash match candidates and avoid sidecar self-match
This commit is contained in:
@@ -234,6 +234,7 @@ def find_metadata_sidecar_path(model_path: str) -> str:
|
||||
|
||||
directory = os.path.dirname(model_path)
|
||||
filename = get_filename_from_path(model_path)
|
||||
normalized_model_path = os.path.normcase(os.path.abspath(model_path))
|
||||
|
||||
# Base name without extension
|
||||
base_name = filename.rsplit(".", 1)[0] if "." in filename else filename
|
||||
@@ -252,6 +253,8 @@ def find_metadata_sidecar_path(model_path: str) -> str:
|
||||
for name in possible_names:
|
||||
if name:
|
||||
path = os.path.join(directory, name)
|
||||
if os.path.normcase(os.path.abspath(path)) == normalized_model_path:
|
||||
continue
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
|
||||
|
||||
@@ -69,6 +69,22 @@ def _clone_hash_match(match: Dict[str, Any]) -> Dict[str, Any]:
|
||||
return cloned
|
||||
|
||||
|
||||
def _is_local_hash_match_candidate(model: Dict[str, Any]) -> bool:
|
||||
model_path = str(model.get("path") or "").strip()
|
||||
if not model_path:
|
||||
return False
|
||||
|
||||
if os.path.isdir(model_path):
|
||||
return True
|
||||
|
||||
filename = get_filename_from_path(model_path).lower()
|
||||
if filename.endswith((".metadata.json", ".civitai.info")):
|
||||
return False
|
||||
|
||||
file_ext = os.path.splitext(filename)[1].lower()
|
||||
return file_ext in _MODEL_EXTENSIONS
|
||||
|
||||
|
||||
def _build_local_hash_match_cache(
|
||||
available_models: List[Dict[str, Any]],
|
||||
) -> Dict[str, List[Dict[str, Any]]]:
|
||||
@@ -76,6 +92,9 @@ def _build_local_hash_match_cache(
|
||||
seen_entries = set()
|
||||
|
||||
for model in available_models:
|
||||
if not _is_local_hash_match_candidate(model):
|
||||
continue
|
||||
|
||||
model_path = model.get("path", "")
|
||||
if not model_path:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user