Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix: only delete individual LoRA file instead of entire parent directory (#8954)

Alexander Eichhorna7b367fda289
diff --git a/invokeai/app/services/model_install/model_install_default.py b/invokeai/app/services/model_install/model_install_default.py
index f20a1784be..8503811bcd 100644
--- a/invokeai/app/services/model_install/model_install_default.py
+++ b/invokeai/app/services/model_install/model_install_default.py
@@ -663,10 +663,12 @@ class ModelInstallService(ModelInstallServiceBase):
# directory. However, the path we store in the model record may be either a file within the key directory,
# or the directory itself. So we have to handle both cases.
if model_path.is_file() or model_path.is_symlink():
- # Sanity check - file models should be in their own directory under the models dir. The parent of the
- # file should be the model's directory, not the Invoke models dir!
- assert model_path.parent != self.app_config.models_path
- rmtree(model_path.parent)
+ # Delete the individual model file, not the entire parent directory.
+ # Other unrelated files may exist in the same directory.
+ model_path.unlink()
+ # Clean up the parent directory only if it is now empty
+ if model_path.parent != self.app_config.models_path and not any(model_path.parent.iterdir()):
+ model_path.parent.rmdir()
elif model_path.is_dir():
# Sanity check - folder models should be in their own directory under the models dir. The path should
# not be the Invoke models dir itself!