Skip to content

Commit

Permalink
Fix mirrored target checks in collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Oct 14, 2024
1 parent ff594e7 commit 87b4017
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion law/target/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87b4017

Please sign in to comment.