From c262f100eced2f8e740e1f1942e8e9a0ca60f2f2 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 20 May 2022 18:24:22 +0000 Subject: [PATCH] Restore proper error for crate not in local reg Fixes #10682. --- src/cargo/sources/registry/local.rs | 13 ++++++++-- tests/testsuite/local_registry.rs | 38 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/cargo/sources/registry/local.rs b/src/cargo/sources/registry/local.rs index 474c5f03b32..a4b57a91e7a 100644 --- a/src/cargo/sources/registry/local.rs +++ b/src/cargo/sources/registry/local.rs @@ -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; @@ -54,8 +54,17 @@ impl<'cfg> RegistryData for LocalRegistry<'cfg> { _index_version: Option<&str>, ) -> Poll> { if self.updated { + let raw_data = match paths::read_bytes(&root.join(path)) { + Err(e) + if e.downcast_ref::() + .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 { diff --git a/tests/testsuite/local_registry.rs b/tests/testsuite/local_registry.rs index 1a9cf1f8cf5..c424f7cbe10 100644 --- a/tests/testsuite/local_registry.rs +++ b/tests/testsuite/local_registry.rs @@ -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();