mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #11783 - arlosi:sparse-offline, r=ehuss
Improve error for missing crate in --offline mode for sparse index This changes sparse registries to instead return `NotFound` when a non-cached crate is requested in `--offline` mode. The resolver can then suggest removing the `--offline` flag if resolution fails, which is a more helpful error than the one currently issued: `attempting to make an HTTP request, but --offline was specified`. With this change, the behavior matches what is already done for git-based registries. Closes #11276
This commit is contained in:
commit
dbb2d67b0c
@ -438,6 +438,13 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
|
|||||||
return Poll::Ready(Ok(LoadResponse::NotFound));
|
return Poll::Ready(Ok(LoadResponse::NotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.config.offline() || self.config.cli_unstable().no_index_update {
|
||||||
|
// Return NotFound in offline mode when the file doesn't exist in the cache.
|
||||||
|
// If this results in resolution failure, the resolver will suggest
|
||||||
|
// removing the --offline flag.
|
||||||
|
return Poll::Ready(Ok(LoadResponse::NotFound));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(result) = self.downloads.results.remove(path) {
|
if let Some(result) = self.downloads.results.remove(path) {
|
||||||
let result =
|
let result =
|
||||||
result.with_context(|| format!("download of {} failed", path.display()))?;
|
result.with_context(|| format!("download of {} failed", path.display()))?;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Tests for the `cargo generate-lockfile` command.
|
//! Tests for the `cargo generate-lockfile` command.
|
||||||
|
|
||||||
use cargo_test_support::registry::Package;
|
use cargo_test_support::registry::{Package, RegistryBuilder};
|
||||||
use cargo_test_support::{basic_manifest, paths, project, ProjectBuilder};
|
use cargo_test_support::{basic_manifest, paths, project, ProjectBuilder};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
@ -57,6 +57,16 @@ fn adding_and_removing_packages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
|
fn no_index_update_sparse() {
|
||||||
|
let _registry = RegistryBuilder::new().http_index().build();
|
||||||
|
no_index_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn no_index_update_git() {
|
||||||
|
no_index_update();
|
||||||
|
}
|
||||||
|
|
||||||
fn no_index_update() {
|
fn no_index_update() {
|
||||||
Package::new("serde", "1.0.0").publish();
|
Package::new("serde", "1.0.0").publish();
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
//! Tests for --offline flag.
|
//! Tests for --offline flag.
|
||||||
|
|
||||||
use cargo_test_support::{basic_manifest, git, main_file, path2url, project, registry::Package};
|
use cargo_test_support::{
|
||||||
|
basic_manifest, git, main_file, path2url, project,
|
||||||
|
registry::{Package, RegistryBuilder},
|
||||||
|
};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
@ -331,7 +334,6 @@ Caused by:
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
|
||||||
fn update_offline_not_cached() {
|
fn update_offline_not_cached() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -362,6 +364,17 @@ retry without the offline flag.",
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn update_offline_not_cached_sparse() {
|
||||||
|
let _registry = RegistryBuilder::new().http_index().build();
|
||||||
|
update_offline_not_cached()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn update_offline_not_cached_git() {
|
||||||
|
update_offline_not_cached()
|
||||||
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn cargo_compile_offline_with_cached_git_dep() {
|
fn cargo_compile_offline_with_cached_git_dep() {
|
||||||
let git_project = git::new("dep1", |project| {
|
let git_project = git::new("dep1", |project| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user