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

Stabilize global cache data tracking. #13492

Merged
merged 1 commit into from Feb 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/cargo/core/global_cache_tracker.rs
Expand Up @@ -354,13 +354,7 @@ impl GlobalCacheTracker {
// provide user feedback) rather than blocking inside sqlite
// (which by default has a short timeout).
let db_path = gctx.assert_package_cache_locked(CacheLockMode::DownloadExclusive, &db_path);
let mut conn = if gctx.cli_unstable().gc {
Connection::open(db_path)?
} else {
// To simplify things (so there aren't checks everywhere for being
// enabled), just process everything in memory.
Connection::open_in_memory()?
};
let mut conn = Connection::open(db_path)?;
conn.pragma_update(None, "foreign_keys", true)?;
sqlite::migrate(&mut conn, &migrations())?;
Ok(GlobalCacheTracker {
Expand Down
31 changes: 14 additions & 17 deletions tests/testsuite/global_cache_tracker.rs
Expand Up @@ -164,23 +164,20 @@ fn rustup_cargo() -> Execs {

#[cargo_test]
fn auto_gc_gated() {
// Requires -Zgc to both track last-use data and to run auto-gc.
// Requires -Zgc to run auto-gc.
let p = basic_foo_bar_project();
p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
// Check that it did not create a database or delete anything.
// Check that it created a database.
let gctx = GlobalContextBuilder::new().build();
assert!(!GlobalCacheTracker::db_path(&gctx)
assert!(GlobalCacheTracker::db_path(&gctx)
.into_path_unlocked()
.exists());
assert_eq!(get_index_names().len(), 1);

// Again in the future, shouldn't auto-gc.
p.cargo("check").run();
assert!(!GlobalCacheTracker::db_path(&gctx)
.into_path_unlocked()
.exists());
assert_eq!(get_index_names().len(), 1);
}

Expand All @@ -203,7 +200,7 @@ See [..]
fn implies_source() {
// Checks that when a src, crate, or checkout is marked as used, the
// corresponding index or git db also gets marked as used.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let _lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -563,7 +560,7 @@ fn auto_gc_various_commands() {
.masquerade_as_nightly_cargo(&["gc"])
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -647,7 +644,7 @@ fn updates_last_use_various_commands() {
.arg("-Zgc")
.masquerade_as_nightly_cargo(&["gc"])
.run();
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -696,7 +693,7 @@ fn both_git_and_http_index_cleans() {
.masquerade_as_nightly_cargo(&["gc"])
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -821,7 +818,7 @@ fn tracks_sizes() {
.run();

// Check that the crate sizes are the same as on disk.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let _lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -863,7 +860,7 @@ fn tracks_sizes() {
#[cargo_test]
fn max_size() {
// Checks --max-crate-size and --max-src-size with various cleaning thresholds.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();

let test_crates = [
// name, age, crate_size, src_size
Expand Down Expand Up @@ -962,7 +959,7 @@ fn max_size_untracked_crate() {
// When a .crate file exists from an older version of cargo that did not
// track sizes, `clean --max-crate-size` should populate the db with the
// sizes.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let cache = paths::home().join(".cargo/registry/cache/example.com-a6c4a5adcb232b9a");
cache.mkdir_p();
paths::home()
Expand Down Expand Up @@ -1003,7 +1000,7 @@ fn max_size_untracked_prepare() -> (GlobalContext, Project) {
let p = basic_foo_bar_project();
p.cargo("fetch").run();
// Pretend it was an older version that did not track last-use.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
GlobalCacheTracker::db_path(&gctx)
.into_path_unlocked()
.rm_rf();
Expand Down Expand Up @@ -1084,7 +1081,7 @@ fn max_download_size() {
// This creates some sample crates of specific sizes, and then tries
// deleting at various specific size thresholds that exercise different
// edge conditions.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();

let test_crates = [
// name, age, crate_size, src_size
Expand Down Expand Up @@ -1339,7 +1336,7 @@ fn clean_syncs_missing_files() {
.run();

// Verify things are tracked.
let gctx = GlobalContextBuilder::new().unstable_flag("gc").build();
let gctx = GlobalContextBuilder::new().build();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down Expand Up @@ -1992,7 +1989,7 @@ fn forward_compatible() {
.masquerade_as_nightly_cargo(&["gc"])
.run();

let config = GlobalContextBuilder::new().unstable_flag("gc").build();
let config = GlobalContextBuilder::new().build();
let lock = config
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
Expand Down