From c9496bcfe3271631124d557af9166c0a2c3879cc Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 7 Dec 2022 12:22:53 +0100 Subject: [PATCH] OP-4504 - change boolean test to validation with exception It actually shouldn't allow to publish into non project folder (like artists own c:/ drive). --- openpype/plugins/publish/integrate.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/openpype/plugins/publish/integrate.py b/openpype/plugins/publish/integrate.py index f3683c4214..5e76521550 100644 --- a/openpype/plugins/publish/integrate.py +++ b/openpype/plugins/publish/integrate.py @@ -293,11 +293,10 @@ class IntegrateAsset(pyblish.api.InstancePlugin): instance) for src, dst in prepared["transfers"]: - if self._are_paths_same(src, dst): - continue + self._validate_path_in_project_roots(anatomy.all_root_paths(), + dst) - if not self._is_path_in_project_roots(anatomy.all_root_paths(), - dst): + if self._are_paths_same(src, dst): continue # todo: add support for hardlink transfers @@ -317,11 +316,10 @@ class IntegrateAsset(pyblish.api.InstancePlugin): ] for files_type, copy_mode in zip(*file_copy_modes): # unpack for src, dst in instance.data.get(files_type, []): + self._validate_path_in_project_roots(anatomy.all_root_paths(), + dst) if self._are_paths_same(src, dst): continue - if not self._is_path_in_project_roots(anatomy.all_root_paths(), - dst): - continue file_transactions.add(src, dst, mode=copy_mode) resource_destinations.add(os.path.abspath(dst)) @@ -910,7 +908,7 @@ class IntegrateAsset(pyblish.api.InstancePlugin): "sites": sites } - def _is_path_in_project_roots(self, roots, file_path): + def _validate_path_in_project_roots(self, roots, file_path): """Checks if 'file_path' starts with any of the roots. Used to check that published path belongs to project, eg. we are not @@ -918,17 +916,17 @@ class IntegrateAsset(pyblish.api.InstancePlugin): Args: roots (list of RootItem): {ROOT_NAME: ROOT_PATH} file_path (str) - Returns: - (bool) + Raises + (KnownPublishError) """ file_path = str(file_path).replace("\\", "/").lower() for root_item in roots: if file_path.startswith(root_item.lower()): return True - self.log.warning( - "Destination '{}' is not in project folder. Skipping" - .format(file_path)) - return False + raise KnownPublishError(( + "Destination path {} ".format(file_path) + + "must be in project dir" + )) def _are_paths_same(self, src, dst): src = str(src).replace("\\", "/").lower()