mirror of
https://github.com/invoke-ai/InvokeAI
synced 2026-03-12 18:00:19 +01:00
fix: only delete individual LoRA file instead of entire parent directory (#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.
This commit is contained in:
parent
cd47b3baf7
commit
a7b367fda2
@ -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!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user