diff --git a/Cargo.toml b/Cargo.toml index 2647fc6..8537237 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 6171a59..34ca61d 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);