Skip to content

Commit

Permalink
Neglect NTFS
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Nov 22, 2024
1 parent 9b543d9 commit e84b99d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 22 additions & 6 deletions src/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use std::{
str::FromStr,
time::{Duration, SystemTime},
};
use tempfile::{tempdir, TempDir};

const DEFAULT_REFRESH_AGE: u64 = 30; // days

Expand All @@ -55,7 +54,7 @@ struct Entry {
}

pub(crate) struct Cache {
tempdir: Option<TempDir>,
tempdir: Option<tempfile::TempDir>,
refresh_age: u64, // days
entries: HashMap<String, Entry>,
repository_timestamps: HashMap<String, SystemTime>,
Expand All @@ -80,6 +79,21 @@ static CACHE_DIRECTORY: Lazy<PathBuf> = Lazy::new(|| {
static CRATES_IO_SYNC_CLIENT: Lazy<SyncClient> =
Lazy::new(|| SyncClient::new(USER_AGENT, RATE_LIMIT).unwrap());

#[cfg(any(feature = "__neglect_ntfs", windows))]
#[allow(clippy::unwrap_used)]
static GIT_CONFIG: Lazy<tempfile::NamedTempFile> = Lazy::new(|| {
use std::io::Write;
let mut tempfile = tempfile::NamedTempFile::new().unwrap();
writeln!(
tempfile,
"\
[core]
protectNTFS = false"
)
.unwrap();
tempfile
});

pub fn with_cache<T>(f: impl FnOnce(&mut Cache) -> T) -> T {
CACHE_ONCE_CELL.with_borrow_mut(|once_cell| {
let _: &Cache = once_cell.get_or_init(|| {
Expand Down Expand Up @@ -107,7 +121,7 @@ pub fn with_cache<T>(f: impl FnOnce(&mut Cache) -> T) -> T {
impl Cache {
fn new(temporary: bool, refresh_age: u64) -> Result<Self> {
let tempdir = if temporary {
tempdir()
tempfile::tempdir()
.map(Option::Some)
.with_context(|| "failed to create temporary directory")?
} else {
Expand Down Expand Up @@ -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:?}"))?;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e84b99d

Please sign in to comment.