-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Added warning when failing to update index cache #15014
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
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,78 @@ fn readonly_registry_still_works() { | |
} | ||
} | ||
|
||
#[cargo_test(ignore_windows = "On Windows setting file attributes is a bit complicated")] | ||
fn unaccessible_registry_cache_still_works() { | ||
Package::new("foo", "0.1.0").publish(); | ||
Package::new("fo2", "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? 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. I was testing with this and notice the dependencies would get compiled in different orders causing But I think this can be worked around by using the Package::new("foo", "0.1.0").publish();
Package::new("fo2", "0.1.0").publish();
// ...
.with_stderr_data(str![[r#"
[WARNING] failed to write cache, path: [ROOT]/home/.cargo/registry/index/-[HASH]/.cache/3/f/fo[..], [ERROR] Permission denied (os error 13)
[COMPILING] fo[..] v0.1.0
[COMPILING] fo[..] v0.1.0
[COMPILING] a v0.5.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]]) I think something like this should. 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. We do have the |
||
fo2 = '0.1.0' | ||
"#, | ||
) | ||
.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/fo[..], [ERROR] Permission denied (os error 13) | ||
[COMPILING] fo[..] v0.1.0 | ||
[COMPILING] fo[..] 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) { | ||
#[cfg(not(windows))] | ||
{ | ||
use std::os::unix::fs::PermissionsExt; | ||
let mut perms = t!(path.metadata()).permissions(); | ||
perms.set_mode(permissions); | ||
t!(fs::set_permissions(path, perms)); | ||
} | ||
|
||
#[cfg(windows)] | ||
panic!("This test is not supported on windows. See the reason in the #[cargo_test] macro"); | ||
} | ||
|
||
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?
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.
Sure, I re-ordered the commits so that the test was added before the fix.
Let me know if I did something incorrectly
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.
My original idea is that both commits should pass CI. And the second commit contains changes in both the logic fix and the test, so the test change could reflect how the behavior has changed with the fix. See this PR as an example #15036. Anyway it doesn't really matter, and thank you!