aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-06-09 17:02:04 +0100
committerJonas Schievink <[email protected]>2021-06-09 17:02:04 +0100
commitd236fc6abecb308dab5e21898fa40f3bddf27640 (patch)
tree3a0cadcc844541fac43b0eab461c4f4f15f50c19 /crates
parent05b3a4bc93cf6555857bfc68b5e85830a0da80dc (diff)
Try to fix unique file names on Windows
Diffstat (limited to 'crates')
-rw-r--r--crates/proc_macro_srv/src/dylib.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/proc_macro_srv/src/dylib.rs b/crates/proc_macro_srv/src/dylib.rs
index cccc53220..5133e7c50 100644
--- a/crates/proc_macro_srv/src/dylib.rs
+++ b/crates/proc_macro_srv/src/dylib.rs
@@ -188,7 +188,9 @@ impl Expander {
188/// Copy the dylib to temp directory to prevent locking in Windows 188/// Copy the dylib to temp directory to prevent locking in Windows
189#[cfg(windows)] 189#[cfg(windows)]
190fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> { 190fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
191 use std::{ffi::OsString, time::SystemTime}; 191 use std::collections::hash_map::RandomState;
192 use std::ffi::OsString;
193 use std::hash::{BuildHasher, Hasher};
192 194
193 let mut to = std::env::temp_dir(); 195 let mut to = std::env::temp_dir();
194 196
@@ -199,10 +201,11 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
199 ) 201 )
200 })?; 202 })?;
201 203
202 // generate a time deps unique number 204 // Generate a unique number by abusing `HashMap`'s hasher.
203 let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards"); 205 // Maybe this will also "inspire" a libs team member to finally put `rand` in libstd.
206 let t = RandomState::new().build_hasher().finish();
204 207
205 let mut unique_name = OsString::from(t.as_millis().to_string()); 208 let mut unique_name = OsString::from(t.to_string());
206 unique_name.push(file_name); 209 unique_name.push(file_name);
207 210
208 to.push(unique_name); 211 to.push(unique_name);