From 9fd3ec5b033ef50da972229f50dd9ce36ca71a12 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 24 Jul 2024 15:54:46 +0200 Subject: [PATCH] only use symlinks from buntar to job --- backend/windmill-worker/src/bun_executor.rs | 57 +++++++++++++-------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/backend/windmill-worker/src/bun_executor.rs b/backend/windmill-worker/src/bun_executor.rs index 322a500776..f375f7a365 100644 --- a/backend/windmill-worker/src/bun_executor.rs +++ b/backend/windmill-worker/src/bun_executor.rs @@ -454,34 +454,48 @@ pub fn copy_recursively( source: impl AsRef, destination: impl AsRef, skip: Option<&Vec>, + no_symlink: bool, ) -> io::Result<()> { - for entry in fs::read_dir(source)? { - let entry = entry?; - let filetype = entry.file_type()?; - let destination = destination.as_ref().join(entry.file_name()); - if let Some(skip) = skip { - if skip.contains(&entry.file_name().to_string_lossy().to_string()) { - continue; + let mut stack = Vec::new(); + stack.push(( + source.as_ref().to_path_buf(), + destination.as_ref().to_path_buf(), + )); + + while let Some((current_source, current_destination)) = stack.pop() { + for entry in fs::read_dir(¤t_source)? { + let entry = entry?; + let filetype = entry.file_type()?; + let destination = current_destination.join(entry.file_name()); + if let Some(skip) = skip { + if skip.contains(&entry.file_name().to_string_lossy().to_string()) { + continue; + } } - } - if filetype.is_dir() { - fs::create_dir_all(&destination)?; - copy_recursively(entry.path(), &destination, None)?; - } else { - let original = entry.path(); - if let Err(e) = fs::hard_link(&original, &destination) { - tracing::error!( - "Could not hard link {original:?} to {destination:?}, trying symlink: {e:#}" - ); - if let Err(e) = std::os::unix::fs::symlink(&original, &destination) { + if filetype.is_dir() { + fs::create_dir_all(&destination)?; + stack.push((entry.path(), destination)); + } else { + let original = entry.path(); + if let Err(e) = fs::hard_link(&original, &destination) { tracing::error!( - "Could not symlink {original:?} to {destination:?}, copying: {e:#}" + "Could not hard link {original:?} to {destination:?}, trying symlink or copy (no_symlink={no_symlink}): {e:#}" ); - fs::copy(&original, &destination)?; + if no_symlink { + fs::copy(&original, &destination)?; + } else { + if let Err(e) = std::os::unix::fs::symlink(&original, &destination) { + tracing::error!( + "Could not symlink {original:?} to {destination:?}, copying: {e:#}" + ); + fs::copy(&original, &destination)?; + } + } } } } } + Ok(()) } @@ -562,7 +576,7 @@ pub async fn handle_bun_job( #[cfg(unix)] if tokio::fs::metadata(&buntar_path).await.is_ok() { - if let Err(e) = copy_recursively(&buntar_path, job_dir, None) { + if let Err(e) = copy_recursively(&buntar_path, job_dir, None, false) { tracing::error!("Could not extract buntar: {e:#}"); } else { gbuntar_name = Some(buntar_name.clone()); @@ -600,6 +614,7 @@ pub async fn handle_bun_job( "shared".to_string(), "bunfig.toml".to_string(), ]), + true, ) { fs::remove_dir_all(&buntar_path)?; tracing::error!("Could not create buntar: {e}");