From 46d07b83377d6c315a2e4e694c68748e9ea3e2ce Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Thu, 2 May 2024 23:36:50 +0200 Subject: [PATCH] fix wrong path bugs --- src/client.rs | 15 +++++++++------ src/client/utils.rs | 28 ++++++++++++++++------------ src/errors.rs | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/client.rs b/src/client.rs index 0318b53..b6278e4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -95,9 +95,7 @@ impl SplitterClient { let duration = Instant::now().duration_since(start_time); info!("FFMPEG-Splitting took: {:?}", duration); let split_info = utils::get_playlist_info(&split_playlist_path).await?; - tokio::fs::remove_file(&split_playlist_path) - .await - .map_err(|e| SplitterError::Write(split_playlist_path.clone(), e))?; + Self::remove_file(&split_playlist_path).await?; trace!( "total duration: {} in {} parts", split_info.total_duration.to_string(), @@ -108,9 +106,7 @@ impl SplitterClient { .await?; debug!("removing original file: {:?}", input_path); - tokio::fs::remove_file(&input_path) - .await - .map_err(|e| SplitterError::Write(input_path.clone(), e))?; + Self::remove_file(&input_path).await?; let duration = Instant::now().duration_since(start_time); info!("Done Splitting. Whole operation took: {:?}", duration); @@ -118,6 +114,13 @@ impl SplitterClient { Ok(paths.len()) } + async fn remove_file(input_path: &PathBuf) -> Result<()> { + tokio::fs::remove_file(&input_path).await.map_err(|e| { + SplitterError::Write(input_path.to_str().unwrap_or("invalid path").to_string(), e) + })?; + Ok(()) + } + #[tracing::instrument(skip(self))] pub async fn split_videos(&self) -> Result<()> { info!("Splitting videos"); diff --git a/src/client/utils.rs b/src/client/utils.rs index c6ceb4c..ce5625a 100644 --- a/src/client/utils.rs +++ b/src/client/utils.rs @@ -75,6 +75,10 @@ async fn join_last_two_parts(input_parts: &mut PlaylistInfo, base_folder: &Path) let second_last_part_path = combine_path_as_string(base_folder, &second_last_part.path)?; let last_part_path = combine_path_as_string(base_folder, &last_part.path)?; let join_txt_path = base_folder.join("join.txt"); + let join_txt_path_string = join_txt_path + .to_str() + .unwrap_or("could not parse to string") + .to_string(); let join_out_tmp_path = base_folder.join("join_out_tmp.mp4"); tokio::fs::write( &join_txt_path, @@ -84,7 +88,7 @@ async fn join_last_two_parts(input_parts: &mut PlaylistInfo, base_folder: &Path) ), ) .await - .map_err(|e| SplitterError::Write(join_txt_path.clone(), e))?; + .map_err(|e| SplitterError::Write(join_txt_path_string.clone(), e))?; run_ffmpeg_concat( join_txt_path @@ -99,27 +103,27 @@ async fn join_last_two_parts(input_parts: &mut PlaylistInfo, base_folder: &Path) .await?; debug!( "removing files: {:?}, {:?}, {:?}", - second_last_part.path, last_part.path, join_txt_path + second_last_part_path, last_part_path, join_txt_path ); - trace!("removing file: {:?}", last_part.path); - tokio::fs::remove_file(&last_part.path) + trace!("removing file: {:?}", last_part_path); + tokio::fs::remove_file(&last_part_path) .await - .map_err(|e| SplitterError::Write(last_part.path, e))?; - trace!("removing file: {:?}", second_last_part.path); - tokio::fs::remove_file(&second_last_part.path) + .map_err(|e| SplitterError::Write(last_part_path, e))?; + trace!("removing file: {:?}", second_last_part_path); + tokio::fs::remove_file(&second_last_part_path) .await - .map_err(|e| SplitterError::Write(second_last_part.path.clone(), e))?; + .map_err(|e| SplitterError::Write(second_last_part_path.clone(), e))?; trace!("removing file: {:?}", join_txt_path); tokio::fs::remove_file(&join_txt_path) .await - .map_err(|e| SplitterError::Write(join_txt_path.clone(), e))?; + .map_err(|e| SplitterError::Write(join_txt_path_string, e))?; debug!( "renaming file: {:?} to {:?}", - join_out_tmp_path, second_last_part.path + join_out_tmp_path, second_last_part_path ); - tokio::fs::rename(join_out_tmp_path, &second_last_part.path) + tokio::fs::rename(join_out_tmp_path, &second_last_part_path) .await - .map_err(|e| SplitterError::Write(second_last_part.path.clone(), e))?; + .map_err(|e| SplitterError::Write(second_last_part_path, e))?; debug!("joined last two parts together"); Ok(()) } diff --git a/src/errors.rs b/src/errors.rs index 25b569b..4ca6d6c 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -19,7 +19,7 @@ pub enum SplitterError { #[error("Could not read from filesystem: {0:?}")] Read(#[source] io::Error), #[error("Could not write to filesystem: {0:?}")] - Write(PathBuf, #[source] io::Error), + Write(String, #[source] io::Error), #[error("Path could not be canonicalized: {0:?}")] Canonicalize(#[source] io::Error),