Skip to content

Commit

Permalink
Overlapping path check too strict
Browse files Browse the repository at this point in the history
Fixes #684
  • Loading branch information
ben-edna committed Mar 7, 2025
1 parent c06b922 commit dd8a23b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dfetch/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import argparse
import os
from pathlib import Path
from typing import Any # pylint: disable=unused-import
from typing import List

Expand Down Expand Up @@ -141,12 +142,23 @@ def _check_overlapping_destination(
real_path: str,
) -> None:
"""Check if project will try to write to the same destination."""
common_prefixes = [
os.path.commonprefix((real_path, dst))
wanted_dest = Path(real_path)

common_paths = [
dst
for dst in destinations
if dst != real_path
if wanted_dest in Path(dst).parents
or Path(dst) in wanted_dest.parents
or wanted_dest == Path(dst)
]
if destinations.count(real_path) > 1 or real_path in common_prefixes:

duplicates = common_paths.count(real_path)
try:
common_paths.remove(real_path)
except ValueError:
pass

if duplicates > 1 or common_paths:
logger.print_warning_line(
project.name,
f'Skipping due to overlapping destination: "{project.destination}"',
Expand Down
21 changes: 21 additions & 0 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,24 @@ def test_check_overlapping_destinations(name, real_path, destinations):
Update._check_overlapping_destination(
ProjectEntry.from_yaml({"name": "a"}), destinations, real_path
)


@pytest.mark.parametrize(
"name, real_path, destinations",
[
(
"sub-folder",
"/somewhere/sub",
["/somewhere/sub", "/somewhere/sub1", "/somewhere/sub2"],
),
(
"sub-folders",
"/somewhere/sub1",
["/somewhere/sub1", "/somewhere/sub/sub1", "/somewhere/sub2"],
),
],
)
def test_check_non_overlapping_destinations(name, real_path, destinations):
Update._check_overlapping_destination(
ProjectEntry.from_yaml({"name": "a"}), destinations, real_path
)

0 comments on commit dd8a23b

Please sign in to comment.