From cc74779e5df38ca7210e99e97a8a4e019b791339 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 20 Feb 2025 12:10:11 +0100 Subject: [PATCH] Fix compilation error on windows I was using unix-specific APIs. --- gdn/src/data/datadir.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gdn/src/data/datadir.rs b/gdn/src/data/datadir.rs index c4ee5bf..a49d560 100644 --- a/gdn/src/data/datadir.rs +++ b/gdn/src/data/datadir.rs @@ -3,7 +3,6 @@ use std::{ fs, io::ErrorKind, ops::Deref, - os::unix::ffi::OsStrExt, path::{Path, PathBuf}, }; @@ -24,9 +23,22 @@ fn tmp_file_name(name: &OsStr) -> OsString { .collect::(); 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(name); tmp_name.push("."); tmp_name.push(random_suffix);