From d236fc6abecb308dab5e21898fa40f3bddf27640 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 9 Jun 2021 18:02:04 +0200 Subject: Try to fix unique file names on Windows --- crates/proc_macro_srv/src/dylib.rs | 11 +++++++---- 1 file 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 { /// Copy the dylib to temp directory to prevent locking in Windows #[cfg(windows)] fn ensure_file_with_lock_free_access(path: &Path) -> io::Result { - use std::{ffi::OsString, time::SystemTime}; + use std::collections::hash_map::RandomState; + use std::ffi::OsString; + use std::hash::{BuildHasher, Hasher}; let mut to = std::env::temp_dir(); @@ -199,10 +201,11 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result { ) })?; - // generate a time deps unique number - let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards"); + // Generate a unique number by abusing `HashMap`'s hasher. + // Maybe this will also "inspire" a libs team member to finally put `rand` in libstd. + let t = RandomState::new().build_hasher().finish(); - let mut unique_name = OsString::from(t.as_millis().to_string()); + let mut unique_name = OsString::from(t.to_string()); unique_name.push(file_name); to.push(unique_name); -- cgit v1.2.3