From 87b4017be7564df7a80ff294cbb729c51bbee46d Mon Sep 17 00:00:00 2001 From: "Marcel R." Date: Mon, 14 Oct 2024 17:34:10 +0200 Subject: [PATCH] Fix mirrored target checks in collections. --- law/target/collection.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/law/target/collection.py b/law/target/collection.py index e3c554e1..29624e17 100644 --- a/law/target/collection.py +++ b/law/target/collection.py @@ -19,6 +19,7 @@ from law.config import Config from law.target.base import Target from law.target.file import FileSystemTarget, FileSystemDirectoryTarget, localize_file_targets +from law.target.mirrored import MirroredTarget, MirroredDirectoryTarget from law.target.local import LocalDirectoryTarget from law.util import colored, flatten, map_struct from law.logger import get_logger @@ -316,9 +317,21 @@ def __init__(self, *args, **kwargs): # check that targets are in fact located in the same directory for t in flatten_collections(self._flat_target_list): - if t.absdirname != self.dir.abspath: + if not self._exists_in_dir(t): raise Exception("{} is not located in common directory {}".format(t, self.dir)) + def _exists_in_dir(self, target): + # comparisons of dirnames are transparently possible for most target classes since their + # paths are consistent, but implement a custom check for mirrored targets + sub_target = target.remote_target if isinstance(target, MirroredTarget) else target + dir_target = ( + self.dir.remote_target + if isinstance(self.dir, MirroredDirectoryTarget) + else self.dir + ) + # do the check + return sub_target.absdirname == dir_target.abspath + def _repr_pairs(self): expand = Config.instance().get_expanded_bool("target", "expand_path_repr") dir_path = self.dir.path if expand else self.dir.unexpanded_path