From 6e8b7213894f05df1f3d671f81dea68d97b2ec2c Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Fri, 15 Mar 2024 16:59:57 -0400 Subject: [PATCH 1/2] Stop registering and moving models which have symlinks in the models dir --- invokeai/app/services/model_install/model_install_default.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/invokeai/app/services/model_install/model_install_default.py b/invokeai/app/services/model_install/model_install_default.py index aff41ee8a7c..f1658b1698e 100644 --- a/invokeai/app/services/model_install/model_install_default.py +++ b/invokeai/app/services/model_install/model_install_default.py @@ -520,7 +520,7 @@ def _sync_model_path(self, key: str) -> AnyModelConfig: new_path = models_dir / model.base.value / model.type.value / old_path.name - if old_path == new_path: + if old_path == new_path or new_path.exists() and old_path == new_path.resolve(): return model self._logger.info(f"Moving {model.name} to {new_path}.") @@ -530,7 +530,7 @@ def _sync_model_path(self, key: str) -> AnyModelConfig: return model def _scan_register(self, model: Path) -> bool: - if model in self._cached_model_paths: + if any(model == m.resolve() for m in self._cached_model_paths): return True try: id = self.register_path(model) From 96453f688eb7c2c04d52583da95a03b69f038b32 Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Fri, 15 Mar 2024 17:07:14 -0400 Subject: [PATCH 2/2] Resolve when instantiating _cached_model_paths --- invokeai/app/services/model_install/model_install_default.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/invokeai/app/services/model_install/model_install_default.py b/invokeai/app/services/model_install/model_install_default.py index f1658b1698e..d6f9792fe78 100644 --- a/invokeai/app/services/model_install/model_install_default.py +++ b/invokeai/app/services/model_install/model_install_default.py @@ -328,7 +328,7 @@ def _migrate_yaml(self) -> None: yaml_path.rename(yaml_path.with_suffix(".yaml.bak")) def scan_directory(self, scan_dir: Path, install: bool = False) -> List[str]: # noqa D102 - self._cached_model_paths = {Path(x.path).absolute() for x in self.record_store.all_models()} + self._cached_model_paths = {Path(x.path).resolve() for x in self.record_store.all_models()} callback = self._scan_install if install else self._scan_register search = ModelSearch(on_model_found=callback) self._models_installed.clear() @@ -530,7 +530,7 @@ def _sync_model_path(self, key: str) -> AnyModelConfig: return model def _scan_register(self, model: Path) -> bool: - if any(model == m.resolve() for m in self._cached_model_paths): + if model in self._cached_model_paths: return True try: id = self.register_path(model)