Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix project files absolute paths when a work copy is used
Browse files Browse the repository at this point in the history
To avoid unintended source code modifications, Cachi2 makes a copy of
the source directory when some package managers are used (currently,
it's being done just for yarn).

This creates a problem with project files, since the absolute path of
files now is pointing to the temporary working copy. The solution
introced by this patch reverts these paths back to the original source
dir path.

This is intended to be a quick fix, and should only be kept until we
solve #712¹.

¹hermetoproject#712

Signed-off-by: Bruno Pimentel <bpimente@redhat.com>
brunoapimentel committed Jan 20, 2025
1 parent b4a413d commit 21750fc
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cachi2/core/resolver.py
Original file line number Diff line number Diff line change
@@ -48,6 +48,12 @@ def resolve_packages(request: Request) -> RequestOutput:
output = _resolve_packages(request)
request.source_dir = original_source_dir

# Temporary solution to project files paths that are pointing to the work copy.
# Should be replaced once we extend the work copy solution to other package managers.
for project_file in output.build_config.project_files:
subpath = project_file.abspath.relative_to(source_backup)
project_file.abspath = original_source_dir / subpath

return output
else:
return _resolve_packages(request)
4 changes: 3 additions & 1 deletion tests/unit/test_resolver.py
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ def test_source_dir_copy(
packages=packages,
)

def _resolve_packages(request: Request) -> None:
def _resolve_packages(request: Request) -> RequestOutput:
if copy_exists:
tmp_dir_name = request.source_dir.path.name

@@ -132,6 +132,8 @@ def _resolve_packages(request: Request) -> None:
# assert the original source_dir is being used
assert request.source_dir == RootedPath(tmp_path)

return RequestOutput.empty()

mock_resolve_packages.side_effect = _resolve_packages

resolver.resolve_packages(request)

0 comments on commit 21750fc

Please sign in to comment.