From a7b367fda289a1cd3227bdc98aa5663c0eb6ce33 Mon Sep 17 00:00:00 2001 From: Alexander Eichhorn Date: Tue, 10 Mar 2026 23:33:08 +0100 Subject: [PATCH] fix: only delete individual LoRA file instead of entire parent directory (#8954) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When deleting a file-based model (e.g. LoRA), the previous logic used rmtree on the parent directory, which would delete all files in that folder — even unrelated ones. Now only the specific model file is removed, and the parent directory is cleaned up only if empty afterward. --- .../services/model_install/model_install_default.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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!