Skip to content

Commit bdce4f6

Browse files
committed
git: Use cfg!() to simplify tempfile code
1 parent 88e900f commit bdce4f6

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
@@ -70,14 +70,15 @@ impl Credentials {
7070
_ => return Err("SSH key not available".into()),
7171
};
7272

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

81+
let mut temp_key_file = tempfile::Builder::new().tempfile_in(dir)?;
8182
temp_key_file.write_all(key.as_bytes())?;
8283

8384
Ok(temp_key_file.into_temp_path())

0 commit comments

Comments
 (0)