From 39863e7f54fa7662c7dd6773d08921cc318f3fb7 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 26 Feb 2024 11:37:54 -0800 Subject: [PATCH] Stabilize global cache data tracking. --- src/cargo/core/global_cache_tracker.rs | 8 +------ tests/testsuite/global_cache_tracker.rs | 31 +++++++++++-------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/cargo/core/global_cache_tracker.rs b/src/cargo/core/global_cache_tracker.rs index bb9385b0a6d..563723b77f1 100644 --- a/src/cargo/core/global_cache_tracker.rs +++ b/src/cargo/core/global_cache_tracker.rs @@ -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 { diff --git a/tests/testsuite/global_cache_tracker.rs b/tests/testsuite/global_cache_tracker.rs index 436013e4e3c..f2bd297525f 100644 --- a/tests/testsuite/global_cache_tracker.rs +++ b/tests/testsuite/global_cache_tracker.rs @@ -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); } @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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 @@ -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() @@ -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(); @@ -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 @@ -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(); @@ -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();