Try to clean up properly even if command errors

This commit is contained in:
asonix 2023-12-23 12:11:15 -06:00
parent 89a4e3995f
commit df8fc00ad5
4 changed files with 17 additions and 9 deletions

View File

@ -211,7 +211,7 @@ where
let tmp_one = (f)(tmp_one).await?; let tmp_one = (f)(tmp_one).await?;
tmp_one.close().await.map_err(FfMpegError::CloseFile)?; tmp_one.close().await.map_err(FfMpegError::CloseFile)?;
let output = Process::run( let res = Process::run(
"ffprobe", "ffprobe",
&[ &[
"-v".as_ref(), "-v".as_ref(),
@ -230,10 +230,12 @@ where
)? )?
.read() .read()
.into_vec() .into_vec()
.await?; .await;
input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?;
let output = res?;
let output: FfMpegDiscovery = serde_json::from_slice(&output).map_err(FfMpegError::Json)?; let output: FfMpegDiscovery = serde_json::from_slice(&output).map_err(FfMpegError::Json)?;
let (discovery, pix_fmt) = parse_discovery(output)?; let (discovery, pix_fmt) = parse_discovery(output)?;

View File

@ -117,7 +117,7 @@ where
let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())]; let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())];
let output = Process::run( let res = Process::run(
"magick", "magick",
&[ &[
"convert".as_ref(), "convert".as_ref(),
@ -130,7 +130,7 @@ where
)? )?
.read() .read()
.into_string() .into_string()
.await?; .await;
input_file.cleanup().await.map_err(MagickError::Cleanup)?; input_file.cleanup().await.map_err(MagickError::Cleanup)?;
temporary_path temporary_path
@ -138,6 +138,8 @@ where
.await .await
.map_err(MagickError::Cleanup)?; .map_err(MagickError::Cleanup)?;
let output = res?;
if output.is_empty() { if output.is_empty() {
return Err(MagickError::Empty); return Err(MagickError::Empty);
} }
@ -183,7 +185,7 @@ where
let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())]; let envs = [(MAGICK_TEMPORARY_PATH, temporary_path.as_os_str())];
let output = Process::run( let res = Process::run(
"magick", "magick",
&[ &[
"convert".as_ref(), "convert".as_ref(),
@ -196,7 +198,7 @@ where
)? )?
.read() .read()
.into_vec() .into_vec()
.await?; .await;
input_file.cleanup().await.map_err(MagickError::Cleanup)?; input_file.cleanup().await.map_err(MagickError::Cleanup)?;
temporary_path temporary_path
@ -204,6 +206,8 @@ where
.await .await
.map_err(MagickError::Cleanup)?; .map_err(MagickError::Cleanup)?;
let output = res?;
if output.is_empty() { if output.is_empty() {
return Err(MagickError::Empty); return Err(MagickError::Empty);
} }

View File

@ -102,8 +102,9 @@ pub(super) async fn thumbnail<S: Store>(
timeout, timeout,
)?; )?;
process.wait().await?; let res = process.wait().await;
input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?;
res?;
let tmp_two = crate::file::File::open(&output_file) let tmp_two = crate::file::File::open(&output_file)
.await .await

View File

@ -34,7 +34,7 @@ pub(super) async fn transcode_bytes(
let output_file = tmp_dir.tmp_file(None); let output_file = tmp_dir.tmp_file(None);
transcode_files( let res = transcode_files(
input_file.as_os_str(), input_file.as_os_str(),
input_format, input_format,
output_file.as_os_str(), output_file.as_os_str(),
@ -42,9 +42,10 @@ pub(super) async fn transcode_bytes(
crf, crf,
timeout, timeout,
) )
.await?; .await;
input_file.cleanup().await.map_err(FfMpegError::Cleanup)?; input_file.cleanup().await.map_err(FfMpegError::Cleanup)?;
res?;
let tmp_two = crate::file::File::open(&output_file) let tmp_two = crate::file::File::open(&output_file)
.await .await