From bfce6573772ebb91a9b1054864c0f53669ceee2f Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 26 Apr 2020 18:52:21 +0800 Subject: Generate uniq name --- crates/ra_proc_macro_srv/src/dylib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'crates/ra_proc_macro_srv') diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs index 209f61493..aa84e951c 100644 --- a/crates/ra_proc_macro_srv/src/dylib.rs +++ b/crates/ra_proc_macro_srv/src/dylib.rs @@ -8,7 +8,6 @@ use goblin::{mach::Mach, Object}; use libloading::Library; use memmap::Mmap; use ra_proc_macro::ProcMacroKind; - use std::io; const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_"; @@ -197,7 +196,10 @@ 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}; + let mut to = std::env::temp_dir(); + let file_name = path.file_name().ok_or_else(|| { io::Error::new( io::ErrorKind::InvalidInput, @@ -205,8 +207,14 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result { ) })?; - to.push(file_name); - std::fs::copy(path, &to)?; + // generate a time deps unique number + let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards"); + + let mut unique_name = OsString::from(t.as_millis().to_string()); + unique_name.push(file_name); + + to.push(unique_name); + std::fs::copy(path, &to).unwrap(); Ok(to) } -- cgit v1.2.3