Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
fs: Fix atomic_write failing on windows if destination is in different drive than the temp dir (#16648)
Cherrye1c42a5c8575
diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rsindex 7473091c489..7635da00170 100644--- a/crates/fs/src/fs.rs+++ b/crates/fs/src/fs.rs@@ -351,6 +351,16 @@ impl Fs for RealFs {// invalid cross-device link error, and XDG_CACHE_DIR for fallback.// See https://github.com/zed-industries/zed/pull/8437 for more details.NamedTempFile::new_in(path.parent().unwrap_or(&paths::temp_dir()))+ } else if cfg!(target_os = "windows") {+ // If temp dir is set to a different drive than the destination,+ // we receive error:+ //+ // failed to persist temporary file:+ // The system cannot move the file to a different disk drive. (os error 17)+ //+ // So we use the directory of the destination as a temp dir to avoid it.+ // https://github.com/zed-industries/zed/issues/16571+ NamedTempFile::new_in(path.parent().unwrap_or(&paths::temp_dir()))} else {NamedTempFile::new()}?;