Skip to content

Commit de0eb0a

Browse files
committed
git: Use cfg!() to simplify tempfile code
1 parent 7f182b4 commit de0eb0a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/git.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ impl Credentials {
6767
_ => return Err("SSH key not available".into()),
6868
};
6969

70-
// When running on production, ensure the file is created in tmpfs and not persisted to disk
71-
#[cfg(target_os = "linux")]
72-
let mut temp_key_file = tempfile::Builder::new().tempfile_in("/dev/shm")?;
73-
74-
// For other platforms, default to std::env::tempdir()
75-
#[cfg(not(target_os = "linux"))]
76-
let mut temp_key_file = tempfile::Builder::new().tempfile()?;
70+
let dir = if cfg!(target_os = "linux") {
71+
// When running on production, ensure the file is created in tmpfs and not persisted to disk
72+
"/dev/shm".into()
73+
} else {
74+
// For other platforms, default to std::env::tempdir()
75+
std::env::temp_dir()
76+
};
7777

78+
let mut temp_key_file = tempfile::Builder::new().tempfile_in(dir)?;
7879
temp_key_file.write_all(key.as_bytes())?;
7980

8081
Ok(temp_key_file.into_temp_path())

0 commit comments

Comments
 (0)