From 4987fe1656d119740c2aef01973309cd130aad77 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 20 Nov 2022 20:46:25 -0500 Subject: [PATCH] Put RocCacheDir::Temp behind #[cfg(test)] --- crates/packaging/Cargo.toml | 5 +++-- crates/packaging/src/cache.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/packaging/Cargo.toml b/crates/packaging/Cargo.toml index 6bb14c94f6..a66df182f5 100644 --- a/crates/packaging/Cargo.toml +++ b/crates/packaging/Cargo.toml @@ -20,8 +20,9 @@ base64-url = "1.4.13" ureq = "2.5.0" bumpalo.workspace = true -tempfile.workspace = true [dev-dependencies] pretty_assertions = "1.3.0" -indoc = "1.0.7" \ No newline at end of file +indoc = "1.0.7" + +tempfile.workspace = true \ No newline at end of file diff --git a/crates/packaging/src/cache.rs b/crates/packaging/src/cache.rs index a108afa1fb..f0ea470bf5 100644 --- a/crates/packaging/src/cache.rs +++ b/crates/packaging/src/cache.rs @@ -5,7 +5,6 @@ use std::{ use roc_error_macros::internal_error; use tar::Archive; -use tempfile::TempDir; use crate::https::{self, PackageMetadata, Problem}; @@ -16,10 +15,11 @@ const TARBALL_BUFFER_SIZE: usize = 16 * 1_000_000; // MB pub enum RocCacheDir<'a> { /// Normal scenario: reading from the user's cache dir on disk Persistent(&'a Path), - /// For tests and such; we don't want to write to the real cache during a test! - Temp(&'a TempDir), - /// Pretty much just for build.rs - we should never be downloading anything; blow up if we try! + /// For build.rs and tests where we never want be downloading anything - yell loudly if we try! Disallowed, + /// For tests only; we don't want to write to the real cache during a test! + #[cfg(test)] + Temp(&'a tempfile::TempDir), } /// Accepts either a path to the Roc cache dir, or else a TempDir. If a TempDir, always download @@ -53,13 +53,14 @@ pub fn install_package<'a>( dest_dir } - RocCacheDir::Temp(temp_dir) => temp_dir.path().to_path_buf(), RocCacheDir::Disallowed => { internal_error!( "Tried to download a package ({:?}) via RocCacheDir::Disallowed - which was explicitly used in order to disallow downloading packages in the current context!", url ) } + #[cfg(test)] + RocCacheDir::Temp(temp_dir) => temp_dir.path().to_path_buf(), }; // Download the tarball into memory and verify it. Early return if it fails verification,