Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vendor): dont remove non-cached source #15260

Merged
merged 2 commits into from
Mar 4, 2025
Merged

Conversation

weihanglo
Copy link
Member

What does this PR try to resolve?

Fixes #15244

With this fix,
cargo vendor will not delete original sources,
if you want to vendor things from one directory sources to the other

Background

cargo-vendor has a workaround that to mitigate #5956:
it removes all cached sources in order to trigger a re-unpack.
It was meant for dealing with registry sources only,
but accidentally applied to directory source kind.

While directory source kind was invented for vendoring,
and vendoring from one vendored directory to the other seems unusual,
Cargo IMO should not delete any real sources.

It does not mean that registry sources are okay to delete,
In long term, we should explore a way that unpacks .crate files
directly, without any removal. See
#12509 (comment)

How should we test and review this PR?

The added test should suffice.

Also, although this is for fixing #15244,
cargo vendor still doesn't support vendor from and to the same location.
Unless we figure out an rsync-like solutin to update vendor sources,
it is not going to support in short term.
(And I also doubt the real world use case of it)

Additional information

Sources like directory sources (which usually are vendored source)
likely contains real sources not cached sources.
Cargo shouldn't delete them.
cargo-vendor has a workaround that to mitigate rust-lang#5956,
it removes all cached sources in order to trigger a re-unpack.
It was meant for dealing with registry sources only, but accidentally
applied to directory source kind.

While directory source kind was invented for vendoring,
and vendoring from one vendored directory to the other seems unusual,
Cargo IMO should not delete any real sources.

It does not mean that registry sources are okay to delete,
In long term, we should explore a way that unpacks `.crate` files
directly, without any removal. See
rust-lang#12509 (comment)
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-vendor S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 4, 2025
@weihanglo weihanglo changed the title test: show problematic behavior that delete non-cached sources fix(vendor): dont remove non-cached source Mar 4, 2025
Comment on lines 167 to 172
}
continue;
}
if pkg.source_id().is_git() {
if sid.is_git() {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rather than ifs with continues that keep falling through cases, it seems like if/else if would better express the mutually exclusive nature of this loop.

Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit is unlikely worth waiting on a merge

@epage epage enabled auto-merge March 4, 2025 02:11
@epage epage added this pull request to the merge queue Mar 4, 2025
Merged via the queue into rust-lang:master with commit 29f8d03 Mar 4, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. Command-vendor S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo vendor --respect-source-config deletes previously vendored sources
4 participants