From 816e11dcc5eafbe54d2ecd4bc525a46f88a3e154 Mon Sep 17 00:00:00 2001 From: Tor Date: Tue, 21 May 2024 11:17:56 +0200 Subject: [PATCH] fix too long filename --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/episode.rs | 9 ++++++++- src/patterns.rs | 1 + src/utils.rs | 6 ------ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0663732..20d759e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1512,7 +1512,7 @@ dependencies = [ [[package]] name = "talecast" -version = "0.1.38" +version = "0.1.39" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index bc6a6bf..1880565 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "talecast" -version = "0.1.38" +version = "0.1.39" edition = "2021" description = "Simple CLI podcatcher" license = "MIT" diff --git a/src/episode.rs b/src/episode.rs index 0b9a9eb..9124c7d 100644 --- a/src/episode.rs +++ b/src/episode.rs @@ -472,10 +472,17 @@ impl<'a> DownloadedEpisode<'a> { fn rename(&mut self) -> Result<(), String> { let new_name = &self.inner.config.name_pattern; - let new_name = sanitize_filename::sanitize(new_name); + let mut new_name = sanitize_filename::sanitize(new_name); let new_path = match self.path.extension() { Some(extension) => { + let max_file_len: usize = 255; + let ext_len = extension.len() + 1; // + 1 for the dot. + let overflow = (new_name.len() + ext_len).saturating_sub(max_file_len); + for _ in 0..overflow { + new_name.pop(); + } + let mut new_path = self.path.with_file_name(new_name); new_path.set_extension(extension); new_path diff --git a/src/patterns.rs b/src/patterns.rs index 733ebec..a64112b 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -225,6 +225,7 @@ use crate::config::EvalData; pub trait Evaluate { fn evaluate(&self, data: EvalData) -> String; + #[allow(dead_code)] fn path_eval(&self, data: EvalData) -> PathBuf { let s = self.evaluate(data); PathBuf::from(s) diff --git a/src/utils.rs b/src/utils.rs index 0743dc0..e33daf7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,7 +2,6 @@ use crate::config; use crate::episode::Episode; use crate::utils; use regex::Regex; -use serde::Serialize; use serde_json::Value; use std::fs; use std::fs::File; @@ -95,11 +94,6 @@ pub fn truncate_string(s: &str, max_width: usize, append_dots: bool) -> String { truncated } -#[derive(Serialize)] -struct BasicPodcast { - url: String, -} - pub fn short_handle_response( response: Result, ) -> Result {