Skip to content

Commit a7b367f

Browse files
fix: only delete individual LoRA file instead of entire parent directory (invoke-ai#8954)
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.
1 parent cd47b3b commit a7b367f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

invokeai/app/services/model_install/model_install_default.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,12 @@ def unconditionally_delete(self, key: str) -> None: # noqa D102
663663
# directory. However, the path we store in the model record may be either a file within the key directory,
664664
# or the directory itself. So we have to handle both cases.
665665
if model_path.is_file() or model_path.is_symlink():
666-
# Sanity check - file models should be in their own directory under the models dir. The parent of the
667-
# file should be the model's directory, not the Invoke models dir!
668-
assert model_path.parent != self.app_config.models_path
669-
rmtree(model_path.parent)
666+
# Delete the individual model file, not the entire parent directory.
667+
# Other unrelated files may exist in the same directory.
668+
model_path.unlink()
669+
# Clean up the parent directory only if it is now empty
670+
if model_path.parent != self.app_config.models_path and not any(model_path.parent.iterdir()):
671+
model_path.parent.rmdir()
670672
elif model_path.is_dir():
671673
# Sanity check - folder models should be in their own directory under the models dir. The path should
672674
# not be the Invoke models dir itself!

0 commit comments

Comments
 (0)