Remove check for models dir in model deletion, update tests to always assume the model path is an absolute path

This commit is contained in:
Brandon Rising
2024-03-08 11:55:28 -05:00
committed by Brandon
parent 6e2cef1db5
commit ee38fbe89c
2 changed files with 23 additions and 19 deletions

View File

@ -344,7 +344,7 @@ class ModelInstallService(ModelInstallServiceBase):
"""Unregister the model. Delete its files only if they are within our models directory."""
model = self.record_store.get_model(key)
models_dir = self.app_config.models_path
model_path = models_dir / model.path
model_path = Path(model.path)
if model_path.is_relative_to(models_dir):
self.unconditionally_delete(key)
else:
@ -352,11 +352,11 @@ class ModelInstallService(ModelInstallServiceBase):
def unconditionally_delete(self, key: str) -> None: # noqa D102
model = self.record_store.get_model(key)
path = self.app_config.models_path / model.path
if path.is_dir():
rmtree(path)
model_path = Path(model.path)
if model_path.is_dir():
rmtree(model_path)
else:
path.unlink()
model_path.unlink()
self.unregister(key)
def download_and_cache(