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

Restore proper error for crate not in local reg #10683

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/cargo/sources/registry/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::util::errors::CargoResult;
use crate::util::{Config, Filesystem};
use cargo_util::{paths, Sha256};
use std::fs::File;
use std::io::prelude::*;
use std::io::SeekFrom;
use std::io::{self, prelude::*};
use std::path::Path;
use std::task::Poll;

Expand Down Expand Up @@ -54,8 +54,17 @@ impl<'cfg> RegistryData for LocalRegistry<'cfg> {
_index_version: Option<&str>,
) -> Poll<CargoResult<LoadResponse>> {
if self.updated {
let raw_data = match paths::read_bytes(&root.join(path)) {
Err(e)
if e.downcast_ref::<io::Error>()
.map_or(false, |ioe| ioe.kind() == io::ErrorKind::NotFound) =>
{
return Poll::Ready(Ok(LoadResponse::NotFound));
}
r => r,
}?;
Poll::Ready(Ok(LoadResponse::Data {
raw_data: paths::read_bytes(&root.join(path))?,
raw_data,
index_version: None,
}))
} else {
Expand Down
38 changes: 38 additions & 0 deletions tests/testsuite/local_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ fn simple() {
p.cargo("test").run();
}

#[cargo_test]
fn not_found() {
setup();
// Publish a package so that the directory hierarchy is created.
// Note, however, that we declare a dependency on baZ.
Package::new("bar", "0.0.1").local(true).publish();

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
baz = "0.0.1"
"#,
)
.file(
"src/lib.rs",
"extern crate baz; pub fn foo() { baz::bar(); }",
)
.build();

p.cargo("build")
.with_status(101)
.with_stderr(
"\
[ERROR] no matching package named `baz` found
location searched: registry `crates-io`
required by package `foo v0.0.1 ([..]/foo)`
",
)
.run();
}

#[cargo_test]
fn depend_on_yanked() {
setup();
Expand Down