From 87757cb66d01bda21f539cc1ee363c7f66741570 Mon Sep 17 00:00:00 2001 From: Dany Gagnon Date: Fri, 25 Jul 2025 04:20:54 -0400 Subject: [PATCH 1/2] fix: crosslink fix --- crates/corrosion/src/command/tpl.rs | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/corrosion/src/command/tpl.rs b/crates/corrosion/src/command/tpl.rs index 481791c6e..446842753 100644 --- a/crates/corrosion/src/command/tpl.rs +++ b/crates/corrosion/src/command/tpl.rs @@ -1,8 +1,5 @@ use std::{ - collections::{HashMap, HashSet}, - env::current_dir, - net::SocketAddr, - time::{Duration, Instant}, + collections::{HashMap, HashSet}, env::current_dir, io::ErrorKind, net::SocketAddr, path::Path, time::{Duration, Instant} }; use camino::Utf8PathBuf; @@ -131,7 +128,10 @@ pub async fn run( debug!("rendered template"); - tokio::fs::rename(&tmp_filepath, &dst).await?; + if let Err(e) = atomic_rename_or_copy(&tmp_filepath, &dst).await { + error!("failed to write {}: {e}", dst); + break; + } debug!("wrote file"); @@ -226,11 +226,8 @@ pub async fn run( tokio::spawn(async_watch(filepaths)); while let Some(res) = futs.next().await { - match res { - Ok(_) => { - info!("") - } - Err(_) => todo!(), + if let Err(ref err) = res { + error!("template task failed: {err:#}"); } println!("got a res: {res:?}"); } @@ -238,6 +235,21 @@ pub async fn run( Ok(()) } +async fn atomic_rename_or_copy( + tmp: &Path, dst: &Utf8PathBuf +) -> eyre::Result<()> { + match tokio::fs::rename(tmp, dst).await { + Ok(()) => Ok(()), + Err(e) if e.raw_os_error() == Some(18) => { // libc::EXDEV cross link + info!("cross-device rename, falling back to copy"); + tokio::fs::copy(tmp, dst).await?; + tokio::fs::remove_file(tmp).await?; + Ok(()) + } + Err(e) => Err(e.into()), + } +} + fn async_watcher() -> notify::Result<(Debouncer, Receiver)> { let (tx, rx) = channel(1); From 83fb5dc620434844e92ca4686ae530a9667776dc Mon Sep 17 00:00:00 2001 From: Dany Gagnon Date: Fri, 25 Jul 2025 04:35:15 -0400 Subject: [PATCH 2/2] chore: fmt tpl --- crates/corrosion/src/command/tpl.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/corrosion/src/command/tpl.rs b/crates/corrosion/src/command/tpl.rs index 446842753..91603ecf7 100644 --- a/crates/corrosion/src/command/tpl.rs +++ b/crates/corrosion/src/command/tpl.rs @@ -1,5 +1,10 @@ use std::{ - collections::{HashMap, HashSet}, env::current_dir, io::ErrorKind, net::SocketAddr, path::Path, time::{Duration, Instant} + collections::{HashMap, HashSet}, + env::current_dir, + io::ErrorKind, + net::SocketAddr, + path::Path, + time::{Duration, Instant}, }; use camino::Utf8PathBuf; @@ -235,12 +240,11 @@ pub async fn run( Ok(()) } -async fn atomic_rename_or_copy( - tmp: &Path, dst: &Utf8PathBuf -) -> eyre::Result<()> { +async fn atomic_rename_or_copy(tmp: &Path, dst: &Utf8PathBuf) -> eyre::Result<()> { match tokio::fs::rename(tmp, dst).await { Ok(()) => Ok(()), - Err(e) if e.raw_os_error() == Some(18) => { // libc::EXDEV cross link + Err(e) if e.raw_os_error() == Some(18) => { + // libc::EXDEV cross link info!("cross-device rename, falling back to copy"); tokio::fs::copy(tmp, dst).await?; tokio::fs::remove_file(tmp).await?;