|
8 | 8 | from copy import deepcopy
|
9 | 9 | from pathlib import Path
|
10 | 10 | from queue import Empty, Queue
|
11 |
| -from shutil import move, rmtree |
| 11 | +from shutil import move |
12 | 12 | from tempfile import mkdtemp
|
13 | 13 | from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union
|
14 | 14 |
|
|
56 | 56 | from invokeai.backend.util import InvokeAILogger
|
57 | 57 | from invokeai.backend.util.catch_sigint import catch_sigint
|
58 | 58 | from invokeai.backend.util.devices import TorchDevice
|
59 |
| -from invokeai.backend.util.util import slugify |
| 59 | +from invokeai.backend.util.util import safe_rmtree, slugify |
60 | 60 |
|
61 | 61 | if TYPE_CHECKING:
|
62 | 62 | from invokeai.app.services.events.events_base import EventServiceBase
|
@@ -376,12 +376,12 @@ def unconditionally_delete(self, key: str) -> None: # noqa D102
|
376 | 376 | # Sanity check - file models should be in their own directory under the models dir. The parent of the
|
377 | 377 | # file should be the model's directory, not the Invoke models dir!
|
378 | 378 | assert model_path.parent != self.app_config.models_path
|
379 |
| - rmtree(model_path.parent) |
| 379 | + safe_rmtree(model_path.parent) |
380 | 380 | elif model_path.is_dir():
|
381 | 381 | # Sanity check - folder models should be in their own directory under the models dir. The path should
|
382 | 382 | # not be the Invoke models dir itself!
|
383 | 383 | assert model_path != self.app_config.models_path
|
384 |
| - rmtree(model_path) |
| 384 | + safe_rmtree(model_path) |
385 | 385 | self.unregister(key)
|
386 | 386 |
|
387 | 387 | @classmethod
|
@@ -511,7 +511,7 @@ def _install_next_item(self) -> None:
|
511 | 511 | finally:
|
512 | 512 | # if this is an install of a remote file, then clean up the temporary directory
|
513 | 513 | if job._install_tmpdir is not None:
|
514 |
| - rmtree(job._install_tmpdir) |
| 514 | + safe_rmtree(job._install_tmpdir) |
515 | 515 | self._install_completed_event.set()
|
516 | 516 | self._install_queue.task_done()
|
517 | 517 | self._logger.info(f"Installer thread {threading.get_ident()} exiting")
|
@@ -556,7 +556,7 @@ def _remove_dangling_install_dirs(self) -> None:
|
556 | 556 | path = self._app_config.models_path
|
557 | 557 | for tmpdir in path.glob(f"{TMPDIR_PREFIX}*"):
|
558 | 558 | self._logger.info(f"Removing dangling temporary directory {tmpdir}")
|
559 |
| - rmtree(tmpdir) |
| 559 | + safe_rmtree(tmpdir) |
560 | 560 |
|
561 | 561 | def _scan_for_missing_models(self) -> list[AnyModelConfig]:
|
562 | 562 | """Scan the models directory for missing models and return a list of them."""
|
|
0 commit comments