Repository navigation
fix(sources): prepare Git checkouts by download kind - #1389
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
rd4398
left a comment
There was a problem hiding this comment.
Thanks, this looks overall good. The tests and docs are thorough too. I have left some comments
|
This pull request has merge conflicts that must be resolved before it can be merged. |
978129b to
8a4057c
Compare
rd4398
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback. This looks good now!
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
There was a problem hiding this comment.
--source-path can cause Fromager to delete the input archive. For example, passing work-dir/demo-1.0/demo-1.0.tar.gz makes unpack_source() delete its containing directory before opening the archive. The command then fails with FileNotFoundError, and the archive is gone.
The cleanup code already exists, but this PR exposes it through the new option. Please reject this location before cleanup and add a test confirming that the archive survives.
Proposed diff in src/fromager/sources.py
@@ -308,5 +308,16 @@
unpack_dir = ctx.work_dir / expected_name
+ resolved_unpack_dir = unpack_dir.resolve()
+ source_paths = (source_filename, *source_filename.parents)
+ if any(
+ path.resolve().is_relative_to(resolved_unpack_dir)
+ for path in source_paths
+ ):
+ raise ValueError(
+ f"source archive {source_filename} overlaps {unpack_dir}; "
+ "move it outside the package work directory before preparing"
+ )
+
if unpack_dir.exists():
if ctx.cleanup:
logger.debug("cleaning up %s", unpack_dir)
shutil.rmtree(unpack_dir)The dangerous line is shutil.rmtree(unpack_dir): it deletes the folder and everything inside it.
The added check runs before deletion. It checks the archive and its parent folders, resolving symlinks, and stops with a clear error if they overlap the folder being cleaned.
The proposed guard passed eight focused path checks. It still needs a regression test in the PR.
Carry DownloadedSource.kind through bootstrap and build entry points. Unpack ordinary archives; prepare clean Git checkouts in place so patches, project overrides, and Rust vendoring run. Keep prepare_source override arguments and path-only callers compatible. Document the public Git helper and no-cleanup behavior, and reject dirty nested submodules before preparation. Reject archive input paths that cleanup would remove before extraction, preserving the input and reporting an actionable error. Closes: python-wheel-build#1205 Co-Authored-By: Codex <noreply@openai.com> Signed-off-by: Shanmukh Pawan <smoparth@redhat.com>
8a4057c to
c5e3a28
Compare
a7bc164
into
python-wheel-build:new-resolver-config
What
are unpacked; clean Git checkouts are prepared in place.
prepare_sourceoverride arguments and path-only callerscompatible. Build metadata is written but is not used to decide
whether preparation runs.
--source-kindtostep prepare-sourceand optional JSON outputto
step download-source-archive. Existing path-only output remainsthe default.
an existing destination raises
FileExistsError.Why
Git resolvers return checkout directories, but preparation previously
tried to unpack those directories as archives.
Closes: #1205
The related
build_sdiststrategy remains in #1206 / #1385. The currentdefault tar builder can include
.git, so Git source builds are not yetproduction-ready. Prebuilt routing remains in #1208.
Testing
Focused tests in
test_sources.py,test_packagesettings_resolver.py,test_bootstrapper.py, andtest_commands.py: 244 passed.File-scoped Ruff and mypy checks passed;
git diff --checkpassed.Full and end-to-end suites were not run.
PR follows CONTRIBUTING.md guidelines