From e84b99d1e5fa44415459455e1082c607f1fa9f8c Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Thu, 21 Nov 2024 18:49:30 -0500 Subject: [PATCH] Neglect NTFS --- Cargo.toml | 1 + src/on_disk_cache.rs | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2647fc66..85372374 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,7 @@ default = ["on-disk-cache", "lock-index"] cache-repositories = ["on-disk-cache"] on-disk-cache = [] lock-index = ["libc", "windows-sys"] +__neglect_ntfs = [] [lints.rust.unexpected_cfgs] level = "deny" diff --git a/src/on_disk_cache.rs b/src/on_disk_cache.rs index 6171a593..34ca61de 100644 --- a/src/on_disk_cache.rs +++ b/src/on_disk_cache.rs @@ -40,7 +40,6 @@ use std::{ str::FromStr, time::{Duration, SystemTime}, }; -use tempfile::{tempdir, TempDir}; const DEFAULT_REFRESH_AGE: u64 = 30; // days @@ -55,7 +54,7 @@ struct Entry { } pub(crate) struct Cache { - tempdir: Option, + tempdir: Option, refresh_age: u64, // days entries: HashMap, repository_timestamps: HashMap, @@ -80,6 +79,21 @@ static CACHE_DIRECTORY: Lazy = Lazy::new(|| { static CRATES_IO_SYNC_CLIENT: Lazy = Lazy::new(|| SyncClient::new(USER_AGENT, RATE_LIMIT).unwrap()); +#[cfg(any(feature = "__neglect_ntfs", windows))] +#[allow(clippy::unwrap_used)] +static GIT_CONFIG: Lazy = Lazy::new(|| { + use std::io::Write; + let mut tempfile = tempfile::NamedTempFile::new().unwrap(); + writeln!( + tempfile, + "\ + [core] + protectNTFS = false" + ) + .unwrap(); + tempfile +}); + pub fn with_cache(f: impl FnOnce(&mut Cache) -> T) -> T { CACHE_ONCE_CELL.with_borrow_mut(|once_cell| { let _: &Cache = once_cell.get_or_init(|| { @@ -107,7 +121,7 @@ pub fn with_cache(f: impl FnOnce(&mut Cache) -> T) -> T { impl Cache { fn new(temporary: bool, refresh_age: u64) -> Result { let tempdir = if temporary { - tempdir() + tempfile::tempdir() .map(Option::Some) .with_context(|| "failed to create temporary directory")? } else { @@ -188,8 +202,10 @@ impl Cache { command .env("GCM_INTERACTIVE", "never") .env("GIT_ASKPASS", "echo") - .env("GIT_TERMINAL_PROMPT", "0") - .stderr(Stdio::piped()); + .env("GIT_TERMINAL_PROMPT", "0"); + #[cfg(any(feature = "__neglect_ntfs", windows))] + command.env("GIT_CONFIG_GLOBAL", GIT_CONFIG.path()); + command.stderr(Stdio::piped()); let output = command .output() .with_context(|| format!("failed to run command: {command:?}"))?; @@ -356,7 +372,7 @@ impl Cache { } fn base_dir(&self) -> &Path { - let base_dir = self.tempdir.as_ref().map(TempDir::path); + let base_dir = self.tempdir.as_ref().map(tempfile::TempDir::path); #[cfg(all(feature = "on-disk-cache", not(windows)))] return base_dir.unwrap_or(&CACHE_DIRECTORY);