Avoid using tmpdir when writing Zed settings.json on macOS (#32976)

Closes: https://github.com/zed-industries/zed/issues/23907

Release Notes:

- macOS: Fixed an issue with writing Zed settings.json if user's home
directory is on a non-root volume.
This commit is contained in:
Peter Tripp 2025-06-21 13:27:06 -04:00 committed by GitHub
parent cb50f07d23
commit 2b3e453d2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -528,14 +528,11 @@ impl Fs for RealFs {
#[cfg(not(target_os = "windows"))]
async fn atomic_write(&self, path: PathBuf, data: String) -> Result<()> {
smol::unblock(move || {
let mut tmp_file = if cfg!(any(target_os = "linux", target_os = "freebsd")) {
// Use the directory of the destination as temp dir to avoid
// invalid cross-device link error, and XDG_CACHE_DIR for fallback.
// See https://github.com/zed-industries/zed/pull/8437 for more details.
tempfile::NamedTempFile::new_in(path.parent().unwrap_or(paths::temp_dir()))
} else {
tempfile::NamedTempFile::new()
}?;
// Use the directory of the destination as temp dir to avoid
// invalid cross-device link error, and XDG_CACHE_DIR for fallback.
// See https://github.com/zed-industries/zed/pull/8437 for more details.
let mut tmp_file =
tempfile::NamedTempFile::new_in(path.parent().unwrap_or(paths::temp_dir()))?;
tmp_file.write_all(data.as_bytes())?;
tmp_file.persist(path)?;
anyhow::Ok(())