Skip to content

Commit bfce657

Browse files
committed
Generate uniq name
1 parent 1836736 commit bfce657

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

crates/ra_proc_macro_srv/src/dylib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use goblin::{mach::Mach, Object};
88
use libloading::Library;
99
use memmap::Mmap;
1010
use ra_proc_macro::ProcMacroKind;
11-
1211
use std::io;
1312

1413
const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_";
@@ -197,16 +196,25 @@ impl Expander {
197196
/// Copy the dylib to temp directory to prevent locking in Windows
198197
#[cfg(windows)]
199198
fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
199+
use std::{ffi::OsString, time::SystemTime};
200+
200201
let mut to = std::env::temp_dir();
202+
201203
let file_name = path.file_name().ok_or_else(|| {
202204
io::Error::new(
203205
io::ErrorKind::InvalidInput,
204206
format!("File path is invalid: {}", path.display()),
205207
)
206208
})?;
207209

208-
to.push(file_name);
209-
std::fs::copy(path, &to)?;
210+
// generate a time deps unique number
211+
let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards");
212+
213+
let mut unique_name = OsString::from(t.as_millis().to_string());
214+
unique_name.push(file_name);
215+
216+
to.push(unique_name);
217+
std::fs::copy(path, &to).unwrap();
210218
Ok(to)
211219
}
212220

0 commit comments

Comments
 (0)