From 7fdc3c8f1fc27be2ca7d4ff62b9fd8ecb3d24e61 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 6 Dec 2023 16:25:24 -0500 Subject: fix(compile/npm): ignore symlinks to non-existent paths in node_modules directory (#21479) Part of https://github.com/denoland/deno/issues/21476 --- cli/tools/compile.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'cli/tools') diff --git a/cli/tools/compile.rs b/cli/tools/compile.rs index ebba884cd..b36ee94bd 100644 --- a/cli/tools/compile.rs +++ b/cli/tools/compile.rs @@ -71,8 +71,9 @@ pub async fn compile( ); validate_output_path(&output_path)?; - let mut file = std::fs::File::create(&output_path)?; - binary_writer + let mut file = std::fs::File::create(&output_path) + .with_context(|| format!("Opening file '{}'", output_path.display()))?; + let write_result = binary_writer .write_bin( &mut file, eszip, @@ -81,8 +82,13 @@ pub async fn compile( cli_options, ) .await - .with_context(|| format!("Writing {}", output_path.display()))?; + .with_context(|| format!("Writing {}", output_path.display())); drop(file); + if let Err(err) = write_result { + // errored, so attempt to remove the output path + let _ = std::fs::remove_file(output_path); + return Err(err); + } // set it as executable #[cfg(unix)] -- cgit v1.2.3