Skip to content

Commit

Permalink
core: utils: _copy_using: Put the dest dir name into the ignore pattern
Browse files Browse the repository at this point in the history
Our default copy destination for the working copies of input
repositories is '.' which means that even the destination directory
(a temporary one) is copied recursively - luckily, the copy backend
seems to be smart enough not to get stuck in an infinite recursion.

Nevertheless, fix the issue by putting the destination dir name into
the ignore pattern of 'shutil.copytree'. This is fine because the
destination name is always going to be unique in our case and hence
there is close to 0% chance of a name collision preventing copying of
some relevant data (in case we don't copy to '.' by default anymore).

Fixes: 2937416

Signed-off-by: Erik Skultety <[email protected]>
  • Loading branch information
eskultety committed Nov 29, 2023
1 parent dfb22fa commit b49e257
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cachi2/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def copy_directory(origin: Path, destination: Path) -> Path:

def _copy_using(copy_function: Callable) -> None:
shutil.copytree(
origin, destination, copy_function=copy_function, dirs_exist_ok=True, symlinks=True
origin,
destination,
copy_function=copy_function,
dirs_exist_ok=True,
symlinks=True,
ignore=shutil.ignore_patterns(destination.name),
)

if reflink.supported_at(origin):
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def test_copy_directory(
else:
copy_function = shutil.copy2

mock_shutil_copytree.assert_called_with(
origin, destination, copy_function=copy_function, dirs_exist_ok=True, symlinks=True
)
assert mock_shutil_copytree.call_args.kwargs["copy_function"] == copy_function


@mock.patch("shutil.copy2")
Expand Down

0 comments on commit b49e257

Please sign in to comment.