Skip to content

cargo vendor --respect-source-config failed with local registry source since 1.89 #16412

@weihanglo

Description

@weihanglo

Problem

Follow the steps below and you'll get

   Vendoring empty-library v1.0.0 (/home/user/.cargo/registry/src/-0f93f6b33946205f/empty-library-1.0.0) to /home/user/projects/foo/vendor/empty-library
error: failed to sync

Caused by:
  failed to open /home/user/.cargo/registry/cache/-0f93f6b33946205f/empty-library-1.0.0.crate

Caused by:
  No such file or directory (os error 2)

This is likely due to #15514, especially the wrong assumption:

/// Unpacks the `.crate` tarball of the package in a given directory.
///
/// Returns the path to the crate tarball directory,
/// which is always `<unpack_dir>/<pkg>-<version>`.
///
/// This holds an assumption that the associated tarball already exists.
pub fn unpack_package_in(
&self,
pkg: &PackageId,
unpack_dir: &Path,
include: &dyn Fn(&Path) -> bool,
) -> CargoResult<PathBuf> {
let path = self.cache_path.join(pkg.tarball_name());
let path = self
.gctx
.assert_package_cache_locked(CacheLockMode::DownloadExclusive, &path);
let dst = unpack_dir.join(format!("{}-{}", pkg.name(), pkg.version()));
let tarball =
File::open(path).with_context(|| format!("failed to open {}", path.display()))?;
unpack(self.gctx, &tarball, &dst, include)?;
update_mtime_for_generated_files(&dst);
Ok(dst)
}

.crate tarballs in local registries are put together with the index (see this).

Steps

First, run cargo install [email protected] to help construct a local registry later.

And also ensure you have Rust toolchain 1.88.0 and 1.89.0 ready

cargo new foo
cd foo
cargo add empty-library
cargo local-registry --sync Cargo.lock my-local-registry

mkdir -p .cargo
cat <<'EOF' > .cargo/config.toml
[source.crates-io]
registry = 'sparse+https://index.crates.io/'
replace-with = 'my-local-registry'

[source.my-local-registry]
local-registry = './my-local-registry'
EOF

And then

# Failed with the error message
cargo +1.89.0 vendor --respect-source-config

# Succeeded
cargo +1.88.0 vendor --respect-source-config

Possible Solution(s)

Perhaps we call download inside RegistrySource::unpack_package_in?

Notes

No response

Version

* GOOD cargo 1.88.0 (873a06493 2025-05-10)
* BAD cargo 1.89.0 (c24e10642 2025-06-23)
* BAD cargo 1.94.0-nightly (e91b2baa6 2025-12-13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-local-registry-sourceArea: local registry sources (vendoring)C-bugCategory: bugCommand-vendorS-needs-mentorStatus: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.regression-from-stable-to-stableRegression in stable that worked in a previous stable release.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions