From c544f167fbee00df9c845f5094a518d790ca06a7 Mon Sep 17 00:00:00 2001 From: asonix Date: Fri, 22 Dec 2023 21:00:37 -0600 Subject: [PATCH] Remove unused code --- src/exiftool.rs | 12 ++++------ src/ffmpeg.rs | 6 +---- src/magick.rs | 31 ------------------------- src/tmp_file.rs | 60 ------------------------------------------------- 4 files changed, 5 insertions(+), 104 deletions(-) diff --git a/src/exiftool.rs b/src/exiftool.rs index 2e6cf59..cc23813 100644 --- a/src/exiftool.rs +++ b/src/exiftool.rs @@ -9,9 +9,6 @@ pub(crate) enum ExifError { #[error("Error in process")] Process(#[source] ProcessError), - #[error("Error reading process output")] - Read(#[source] std::io::Error), - #[error("Invalid media file provided")] CommandFailed(ProcessError), } @@ -29,16 +26,15 @@ impl ExifError { pub(crate) const fn error_code(&self) -> ErrorCode { match self { Self::Process(e) => e.error_code(), - Self::Read(_) => ErrorCode::COMMAND_ERROR, Self::CommandFailed(_) => ErrorCode::COMMAND_FAILURE, } } pub(crate) fn is_client_error(&self) -> bool { // if exiftool bails we probably have bad input - matches!( - self, - Self::CommandFailed(_) | Self::Process(ProcessError::Timeout(_)) - ) + match self { + Self::CommandFailed(_) => true, + Self::Process(e) => e.is_client_error(), + } } } diff --git a/src/ffmpeg.rs b/src/ffmpeg.rs index 330ba28..b55476e 100644 --- a/src/ffmpeg.rs +++ b/src/ffmpeg.rs @@ -5,9 +5,6 @@ pub(crate) enum FfMpegError { #[error("Error in ffmpeg process")] Process(#[source] ProcessError), - #[error("Error reading output")] - Read(#[source] std::io::Error), - #[error("Error writing bytes")] Write(#[source] std::io::Error), @@ -51,8 +48,7 @@ impl FfMpegError { Self::CommandFailed(_) => ErrorCode::COMMAND_FAILURE, Self::Store(s) => s.error_code(), Self::Process(e) => e.error_code(), - Self::Read(_) - | Self::Write(_) + Self::Write(_) | Self::Json(_) | Self::CreateDir(_) | Self::ReadFile(_) diff --git a/src/magick.rs b/src/magick.rs index 3ac47d1..05edbb1 100644 --- a/src/magick.rs +++ b/src/magick.rs @@ -23,9 +23,6 @@ pub(crate) enum MagickError { #[error("Invalid output format")] Json(#[source] serde_json::Error), - #[error("Error reading bytes")] - Read(#[source] std::io::Error), - #[error("Error writing bytes")] Write(#[source] std::io::Error), @@ -67,7 +64,6 @@ impl MagickError { Self::Store(e) => e.error_code(), Self::Process(e) => e.error_code(), Self::Json(_) - | Self::Read(_) | Self::Write(_) | Self::CreateFile(_) | Self::CreateDir(_) @@ -185,33 +181,6 @@ pub(crate) async fn process_image_store_read( .await } -pub(crate) async fn process_image_async_read( - tmp_dir: &TmpDir, - async_read: A, - args: Vec, - input_format: ProcessableFormat, - format: ProcessableFormat, - quality: Option, - timeout: u64, -) -> Result { - process_image( - tmp_dir, - args, - input_format, - format, - quality, - timeout, - |mut tmp_file| async move { - tmp_file - .write_from_async_read(async_read) - .await - .map_err(MagickError::Write)?; - Ok(tmp_file) - }, - ) - .await -} - pub(crate) async fn process_image_process_read( tmp_dir: &TmpDir, process_read: ProcessRead, diff --git a/src/tmp_file.rs b/src/tmp_file.rs index bd7ee7b..440422e 100644 --- a/src/tmp_file.rs +++ b/src/tmp_file.rs @@ -67,15 +67,6 @@ impl Drop for TmpDir { #[must_use] pub(crate) struct TmpFolder(Arc); -impl TmpFolder { - pub(crate) fn reader(self, reader: R) -> TmpFolderCleanup { - TmpFolderCleanup { - inner: reader, - folder: self, - } - } -} - impl AsRef for TmpFolder { fn as_ref(&self) -> &Path { &self.0 @@ -102,15 +93,6 @@ impl Drop for TmpFolder { #[must_use] pub(crate) struct TmpFile(Arc); -impl TmpFile { - pub(crate) fn reader(self, reader: R) -> TmpFileCleanup { - TmpFileCleanup { - inner: reader, - file: self, - } - } -} - impl AsRef for TmpFile { fn as_ref(&self) -> &Path { &self.0 @@ -130,45 +112,3 @@ impl Drop for TmpFile { crate::sync::spawn("remove-tmpfile", tokio::fs::remove_file(self.0.clone())); } } - -pin_project_lite::pin_project! { - pub(crate) struct TmpFileCleanup { - #[pin] - inner: R, - - file: TmpFile, - } -} - -pin_project_lite::pin_project! { - pub(crate) struct TmpFolderCleanup { - #[pin] - inner: R, - - folder: TmpFolder, - } -} - -impl AsyncRead for TmpFileCleanup { - fn poll_read( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - buf: &mut tokio::io::ReadBuf<'_>, - ) -> std::task::Poll> { - let this = self.as_mut().project(); - - this.inner.poll_read(cx, buf) - } -} - -impl AsyncRead for TmpFolderCleanup { - fn poll_read( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - buf: &mut tokio::io::ReadBuf<'_>, - ) -> std::task::Poll> { - let this = self.as_mut().project(); - - this.inner.poll_read(cx, buf) - } -}