-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: Added warning when failing to update index cache #15014
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
use std::fmt::Write; | ||
use std::fs::{self, File}; | ||
use std::path::Path; | ||
use std::path::{Path, PathBuf}; | ||
use std::sync::Arc; | ||
use std::sync::Mutex; | ||
|
||
|
@@ -3097,6 +3097,70 @@ fn readonly_registry_still_works() { | |
} | ||
} | ||
|
||
#[cargo_test] | ||
#[cfg(not(windows))] | ||
Comment on lines
+3100
to
+3101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder why it cannot be done on Windows. Is it possible to use |
||
fn unaccessible_registry_cache_still_works() { | ||
Package::new("foo", "0.1.0").publish(); | ||
|
||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "a" | ||
version = "0.5.0" | ||
edition = "2015" | ||
authors = [] | ||
|
||
[dependencies] | ||
foo = '0.1.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add more than one dependency, so we know it really emits only once? |
||
"#, | ||
) | ||
.file("src/lib.rs", "") | ||
.build(); | ||
|
||
p.cargo("generate-lockfile").run(); | ||
p.cargo("fetch --locked").run(); | ||
|
||
let cache_path = inner_dir(&paths::cargo_home().join("registry/index")).join(".cache"); | ||
let f_cache_path = cache_path.join("3/f"); | ||
|
||
// Remove the permissions from the cache path that contains the "foo" crate | ||
set_permissions(&f_cache_path, 0o000); | ||
|
||
// Now run a build and make sure we properly build and warn the user | ||
p.cargo("build") | ||
.with_stderr_data(str![[r#" | ||
[WARNING] failed to write cache, path: [ROOT]/home/.cargo/registry/index/-[HASH]/.cache/3/f/foo, [ERROR] Permission denied (os error 13) | ||
[COMPILING] foo v0.1.0 | ||
[COMPILING] a v0.5.0 ([ROOT]/foo) | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
// make sure we add the permissions to the files afterwards so "cargo clean" can remove them (#6934) | ||
set_permissions(&f_cache_path, 0o777); | ||
|
||
fn set_permissions(path: &Path, permissions: u32) { | ||
use std::os::unix::fs::PermissionsExt; | ||
let mut perms = t!(path.metadata()).permissions(); | ||
perms.set_mode(permissions); | ||
t!(fs::set_permissions(path, perms)); | ||
} | ||
|
||
fn inner_dir(path: &Path) -> PathBuf { | ||
for entry in t!(path.read_dir()) { | ||
let path = t!(entry).path(); | ||
|
||
if path.is_dir() { | ||
return path; | ||
} | ||
} | ||
|
||
panic!("could not find inner directory of {path:?}"); | ||
} | ||
} | ||
|
||
#[cargo_test] | ||
fn registry_index_rejected_http() { | ||
let _server = setup_http(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a similar test, maybe we can take reuse that test to assert their stderr?
cargo/tests/testsuite/registry.rs
Lines 3053 to 3098 in 2939e96
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I was able to use this to create a test based off of this in 9f2d0a3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shameless copied from #15026 (comment).
Mind doing that?