Skip to content

Commit 11d4599

Browse files
committed
Auto merge of #10683 - jonhoo:fix-10682, r=Eh2406
Restore proper error for crate not in local reg Fixes #10682.
2 parents d986288 + c262f10 commit 11d4599

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/cargo/sources/registry/local.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::util::errors::CargoResult;
44
use crate::util::{Config, Filesystem};
55
use cargo_util::{paths, Sha256};
66
use std::fs::File;
7-
use std::io::prelude::*;
87
use std::io::SeekFrom;
8+
use std::io::{self, prelude::*};
99
use std::path::Path;
1010
use std::task::Poll;
1111

@@ -54,8 +54,17 @@ impl<'cfg> RegistryData for LocalRegistry<'cfg> {
5454
_index_version: Option<&str>,
5555
) -> Poll<CargoResult<LoadResponse>> {
5656
if self.updated {
57+
let raw_data = match paths::read_bytes(&root.join(path)) {
58+
Err(e)
59+
if e.downcast_ref::<io::Error>()
60+
.map_or(false, |ioe| ioe.kind() == io::ErrorKind::NotFound) =>
61+
{
62+
return Poll::Ready(Ok(LoadResponse::NotFound));
63+
}
64+
r => r,
65+
}?;
5766
Poll::Ready(Ok(LoadResponse::Data {
58-
raw_data: paths::read_bytes(&root.join(path))?,
67+
raw_data,
5968
index_version: None,
6069
}))
6170
} else {

tests/testsuite/local_registry.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,44 @@ fn simple() {
6262
p.cargo("test").run();
6363
}
6464

65+
#[cargo_test]
66+
fn not_found() {
67+
setup();
68+
// Publish a package so that the directory hierarchy is created.
69+
// Note, however, that we declare a dependency on baZ.
70+
Package::new("bar", "0.0.1").local(true).publish();
71+
72+
let p = project()
73+
.file(
74+
"Cargo.toml",
75+
r#"
76+
[project]
77+
name = "foo"
78+
version = "0.0.1"
79+
authors = []
80+
81+
[dependencies]
82+
baz = "0.0.1"
83+
"#,
84+
)
85+
.file(
86+
"src/lib.rs",
87+
"extern crate baz; pub fn foo() { baz::bar(); }",
88+
)
89+
.build();
90+
91+
p.cargo("build")
92+
.with_status(101)
93+
.with_stderr(
94+
"\
95+
[ERROR] no matching package named `baz` found
96+
location searched: registry `crates-io`
97+
required by package `foo v0.0.1 ([..]/foo)`
98+
",
99+
)
100+
.run();
101+
}
102+
65103
#[cargo_test]
66104
fn depend_on_yanked() {
67105
setup();

0 commit comments

Comments
 (0)