You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cargo package --list --manifest-path in a workspace prints only Cargo.lock on macos #10478
While cargo cargo package --list itself works on all platforms and cargo package --list --manifest-path works on linux and windows, cargo package --list --manifest-path on mac in a workspace prints only Cargo.lock
I believe the root cause is that on macOS /tmp symlinks to /private/tmp, but Cargo does not handle symlinks and path canonicalization well for many places.
Repository::workdir() from git2 resolves the symlink whereas Package::manifest_path() does not. That results in a failure from if let Ok(status) = repo.status_file(path).
let path = path.strip_prefix(workdir).unwrap_or(path);
ifletOk(status) = repo.status_file(path){
if(status & git2::Status::IGNORED).is_empty(){
debug!(
"found (git) Cargo.toml at {:?} in workdir {:?}",
path, workdir
);
let path_in_vcs = path
.parent()
.and_then(|p| p.to_str())
.unwrap_or("")
.replace("\\","/");
returnOk(Some(VcsInfo{
git:git(p, src_files,&repo)?,
path_in_vcs,
}));
}
}
config.shell().verbose(|shell| {
shell.warn(format!(
"No (git) Cargo.toml found at `{}` in workdir `{}`",
path.display(),
workdir.display()
))
})?;
Although Cargo is a bit conservative on symlink resolving (see this), personally I feel like in this particular case it might be worth doing that. See #10478 (comment)
// Filter out files blatantly outside this package. This is helped a
// bit above via the `pathspec` function call, but we need to filter
// the entries in the index as well.
if !file_path.starts_with(pkg_path){
continue;
}
for example, when file_path = /private/tmp/resvg/version-bump.md and pkg_path = /tmp/resvg, apparently file_path is canonicalized while pkg_path isn't.
@messense you're right. What I found is the result, not the cause. Sorry about the misleading.
BTW, I found it by making cargo package verbose.
$ cd / && cargo package --list --manifest-path /tmp/a-project/Cargo.toml --verbosewarning: No (git) Cargo.toml found at `/tmp/a-project/Cargo.toml` in workdir `/private/tmp/a-project/`Cargo.lock
Activity
weihanglo commentedon Mar 14, 2022
I believe the root cause is that on macOS
/tmpsymlinks to/private/tmp, but Cargo does not handle symlinks and path canonicalization well for many places.Repository::workdir()from git2 resolves the symlink whereasPackage::manifest_path()does not. That results in a failure fromif let Ok(status) = repo.status_file(path).cargo/src/cargo/ops/cargo_package.rs
Lines 405 to 430 in b816d82
Although Cargo is a bit conservative on symlink resolving (see this), personally I feel like in this particular case it might be worth doing that.See #10478 (comment)messense commentedon Mar 14, 2022
messense commentedon Mar 14, 2022
Actually we run
cargo package --list --allow-dirtyin maturin:https://github.com/PyO3/maturin/blob/95090d027aeca1fae80c0c9fe19ae18f803db8a3/src/source_distribution.rs#L134
so I think the code in
check_repo_statefunction referenced by @weihanglo isn't even runned.Add a
println!("{:?}", src_files);aftercargo/src/cargo/ops/cargo_package.rs
Line 97 in b816d82
[].messense commentedon Mar 14, 2022
I think the culprit is this code
cargo/src/cargo/sources/path.rs
Lines 293 to 298 in b816d82
for example, when
file_path = /private/tmp/resvg/version-bump.mdandpkg_path = /tmp/resvg, apparentlyfile_pathis canonicalized whilepkg_pathisn't.weihanglo commentedon Mar 14, 2022
@messense you're right. What I found is the result, not the cause. Sorry about the misleading.
BTW, I found it by making
cargo packageverbose.messense commentedon Mar 15, 2022
So this patch fixes the problem, but I'm not sure it is the right fix since
pkg.root()is used in a lot of places.weihanglo commentedon Dec 29, 2024
This has been fixed by switching to gitoxide for file listing (#13592). I've run the MRE and no issue in 1.79.0 and after, so close as resolved.
If there is anything I missed, let us know.