Fix compilation error on windows

I was using unix-specific APIs.
This commit is contained in:
Joscha 2025-02-20 12:10:11 +01:00
parent 4909aa0a29
commit cc74779e5d

View file

@ -3,7 +3,6 @@ use std::{
fs, fs,
io::ErrorKind, io::ErrorKind,
ops::Deref, ops::Deref,
os::unix::ffi::OsStrExt,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@ -24,9 +23,22 @@ fn tmp_file_name(name: &OsStr) -> OsString {
.collect::<String>(); .collect::<String>();
let mut tmp_name = OsString::new(); let mut tmp_name = OsString::new();
if !tmp_name.as_bytes().starts_with(b".") {
// Ensure temporary file always starts with a '.', i.e. it is hidden.
#[cfg(unix)]
let starts_with_dot = {
use std::os::unix::ffi::OsStrExt;
tmp_name.as_bytes().starts_with(b".")
};
#[cfg(windows)]
let starts_with_dot = {
use std::os::windows::ffi::OsStrExt;
tmp_name.encode_wide().next() == Some(b'.' as u16)
};
if !starts_with_dot {
tmp_name.push("."); tmp_name.push(".");
} }
tmp_name.push(name); tmp_name.push(name);
tmp_name.push("."); tmp_name.push(".");
tmp_name.push(random_suffix); tmp_name.push(random_suffix);