From 2d86f0ee7c752180a0ded81f412194cb6083347b Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 21 Mar 2022 17:30:47 +0100 Subject: [PATCH] added check of unknown files in temp --- openpype/tools/workfiles/lib.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/openpype/tools/workfiles/lib.py b/openpype/tools/workfiles/lib.py index c181e634d6..84f2e76450 100644 --- a/openpype/tools/workfiles/lib.py +++ b/openpype/tools/workfiles/lib.py @@ -142,7 +142,9 @@ class TempPublishFiles(object): data = self._get_data() now = time.time() remove_ids = set() + all_ids = set() for item_id, item_data in data.items(): + all_ids.add(item_id) if check_expiration and now < item_data["expiration"]: continue @@ -159,6 +161,23 @@ class TempPublishFiles(object): exc_info=True ) + # Remove unknown folders/files + for filename in os.listdir(self._root_dir): + if filename in all_ids: + continue + + full_path = os.path.join(self._root_dir, filename) + if full_path in (self._metadata_path, self._lock_path): + continue + + try: + shutil.rmtree(full_path) + except Exception: + self.log.warning( + "Couldn't remove arbitrary path \"{}\"".format(full_path), + exc_info=True + ) + def clear(self): self.cleanup(False)