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

Improve error for missing crate in --offline mode for sparse index #11783

Merged
merged 1 commit into from
Mar 1, 2023
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
7 changes: 7 additions & 0 deletions src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
return Poll::Ready(Ok(LoadResponse::NotFound));
}

if self.config.offline() || self.config.cli_unstable().no_index_update {
arlosi marked this conversation as resolved.
Show resolved Hide resolved
// 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) {
let result =
result.with_context(|| format!("download of {} failed", path.display()))?;
Expand Down
12 changes: 11 additions & 1 deletion tests/testsuite/generate_lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! 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 std::fs;

Expand Down Expand Up @@ -57,6 +57,16 @@ fn adding_and_removing_packages() {
}

#[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() {
Package::new("serde", "1.0.0").publish();

Expand Down
17 changes: 15 additions & 2 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! 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;

#[cargo_test]
Expand Down Expand Up @@ -331,7 +334,6 @@ Caused by:
.run();
}

#[cargo_test]
fn update_offline_not_cached() {
let p = project()
.file(
Expand Down Expand Up @@ -362,6 +364,17 @@ retry without the offline flag.",
.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]
fn cargo_compile_offline_with_cached_git_dep() {
let git_project = git::new("dep1", |project| {
Expand Down