From df8fc00ad54967875b7119921e5fc3b9b3c3f9d2 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 23 Dec 2023 12:11:15 -0600 Subject: [PATCH] Try to clean up properly even if command errors --- src/discover/ffmpeg.rs | 6 ++++-- src/discover/magick.rs | 12 ++++++++---- src/generate/ffmpeg.rs | 3 ++- src/validate/ffmpeg.rs | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/discover/ffmpeg.rs b/src/discover/ffmpeg.rs index d1bc06f..e92425b 100644 --- a/src/discover/ffmpeg.rs +++ b/src/discover/ffmpeg.rs @@ -211,7 +211,7 @@ where let tmp_one = (f)(tmp_one).await?; tmp_one.close().await.map_err(FfMpegError::CloseFile)?; - let output = Process::run( + let res = Process::run( "ffprobe", &[ "-v".as_ref(), @@ -230,10 +230,12 @@ where )? .read() .into_vec() - .await?; + .await; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; + let output = res?; + let output: FfMpegDiscovery = serde_json::from_slice(&output).map_err(FfMpegError::Json)?; let (discovery, pix_fmt) = parse_discovery(output)?; diff --git a/src/discover/magick.rs b/src/discover/magick.rs index 72051a1..aac38ae 100644 --- a/src/discover/magick.rs +++ b/src/discover/magick.rs @@ -117,7 +117,7 @@ where let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())]; - let output = Process::run( + let res = Process::run( "magick", &[ "convert".as_ref(), @@ -130,7 +130,7 @@ where )? .read() .into_string() - .await?; + .await; input_file.cleanup().await.map_err(MagickError::Cleanup)?; temporary_path @@ -138,6 +138,8 @@ where .await .map_err(MagickError::Cleanup)?; + let output = res?; + if output.is_empty() { return Err(MagickError::Empty); } @@ -183,7 +185,7 @@ where let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())]; - let output = Process::run( + let res = Process::run( "magick", &[ "convert".as_ref(), @@ -196,7 +198,7 @@ where )? .read() .into_vec() - .await?; + .await; input_file.cleanup().await.map_err(MagickError::Cleanup)?; temporary_path @@ -204,6 +206,8 @@ where .await .map_err(MagickError::Cleanup)?; + let output = res?; + if output.is_empty() { return Err(MagickError::Empty); } diff --git a/src/generate/ffmpeg.rs b/src/generate/ffmpeg.rs index 0311347..ab73097 100644 --- a/src/generate/ffmpeg.rs +++ b/src/generate/ffmpeg.rs @@ -102,8 +102,9 @@ pub(super) async fn thumbnail( timeout, )?; - process.wait().await?; + let res = process.wait().await; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; + res?; let tmp_two = crate::file::File::open(&output_file) .await diff --git a/src/validate/ffmpeg.rs b/src/validate/ffmpeg.rs index ae828ce..1ab7758 100644 --- a/src/validate/ffmpeg.rs +++ b/src/validate/ffmpeg.rs @@ -34,7 +34,7 @@ pub(super) async fn transcode_bytes( let output_file = tmp_dir.tmp_file(None); - transcode_files( + let res = transcode_files( input_file.as_os_str(), input_format, output_file.as_os_str(), @@ -42,9 +42,10 @@ pub(super) async fn transcode_bytes( crf, timeout, ) - .await?; + .await; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; + res?; let tmp_two = crate::file::File::open(&output_file) .await