From b3d7b5274babdab3a6269021286b5aa01c271c72 Mon Sep 17 00:00:00 2001 From: rm-dr <96270320+rm-dr@users.noreply.github.com> Date: Sun, 13 Jul 2025 17:20:09 +0000 Subject: [PATCH] Clippy --- Cargo.toml | 1 - src/main.rs | 4 +- src/manifest/rule.rs | 2 +- src/manifest/types.rs | 4 +- src/prepare.rs | 4 +- src/tool/bash.rs | 6 +-- test.toml | 109 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 test.toml diff --git a/Cargo.toml b/Cargo.toml index 4930160..8a61477 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ use_debug = "allow" verbose_file_reads = "deny" large_types_passed_by_value = "deny" large_enum_variant = "allow" -match_on_vec_items = "deny" wildcard_dependencies = "deny" negative_feature_names = "deny" redundant_feature_names = "deny" diff --git a/src/main.rs b/src/main.rs index 30765d7..406c986 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,6 +88,7 @@ fn main_inner() -> Result { let max_tasks = manifest.config.threads.map(|x| x.get()).unwrap_or(1); debug!("Starting runtime with {max_tasks} threads"); + #[expect(clippy::unwrap_used)] let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(3) .max_blocking_threads(max_tasks) @@ -116,12 +117,13 @@ fn main_inner() -> Result { }); if js.len() >= max_tasks { + #[expect(clippy::unwrap_used)] js.join_next().await.unwrap()??; } } while let Some(x) = js.join_next().await { - x.unwrap()? + x?? } return Ok::<_, Error>(()); diff --git a/src/manifest/rule.rs b/src/manifest/rule.rs index b2b87cc..b671b9c 100644 --- a/src/manifest/rule.rs +++ b/src/manifest/rule.rs @@ -1,4 +1,4 @@ -use anyhow::{Result, bail}; +use anyhow::{bail, Result}; use regex::Regex; use tracing::warn; diff --git a/src/manifest/types.rs b/src/manifest/types.rs index 611cedb..da899f6 100644 --- a/src/manifest/types.rs +++ b/src/manifest/types.rs @@ -190,7 +190,7 @@ impl Iterator for PickRuleIterator<'_> { match value { PickRule::Plain(task) => { let mut patterns = current.prefix.clone(); - patterns.push(key.to_string()); + patterns.push(key.to_owned()); Some(FlatPickRule { patterns, @@ -199,7 +199,7 @@ impl Iterator for PickRuleIterator<'_> { } PickRule::Nested(nested_rules) => { let mut prefix = current.prefix.clone(); - prefix.push(key.to_string()); + prefix.push(key.to_owned()); self.stack.push(PickRuleIterState { rules: nested_rules, diff --git a/src/prepare.rs b/src/prepare.rs index a8706a2..b97c420 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -1,4 +1,4 @@ -use anyhow::{Context, Result, bail}; +use anyhow::{bail, Context, Result}; use indicatif::ProgressBar; use std::{ path::{Path, PathBuf}, @@ -7,7 +7,7 @@ use std::{ use tracing::{error, trace}; use walkdir::WalkDir; -use crate::{Cli, manifest::types::Manifest, style::spinner_style_list, tool::TaskContext}; +use crate::{manifest::types::Manifest, style::spinner_style_list, tool::TaskContext, Cli}; pub fn load_manifest(cli: &Cli) -> Result { let manifest_path_str = cli diff --git a/src/tool/bash.rs b/src/tool/bash.rs index 1473c80..92886cf 100644 --- a/src/tool/bash.rs +++ b/src/tool/bash.rs @@ -34,7 +34,7 @@ impl PickTool for ToolBash { debug!("Running `before` script"); let mut temp_file = tempfile::NamedTempFile::new().context("while creating temporary script")?; - writeln!(temp_file, "{}", script).context("while creating temporary script")?; + writeln!(temp_file, "{script}").context("while creating temporary script")?; temp_file } }; @@ -82,7 +82,7 @@ impl PickTool for ToolBash { debug!("Running `after` script"); let mut temp_file = tempfile::NamedTempFile::new().context("while creating temporary script")?; - writeln!(temp_file, "{}", script).context("while creating temporary script")?; + writeln!(temp_file, "{script}").context("while creating temporary script")?; temp_file } }; @@ -131,7 +131,7 @@ impl PickTool for ToolBash { trace!("Running script for {}: {}", ctx.path_rel_str, ctx.task); let mut temp_file = tempfile::NamedTempFile::new().context("while creating temporary script")?; - writeln!(temp_file, "{}", script).context("while creating temporary script")?; + writeln!(temp_file, "{script}").context("while creating temporary script")?; temp_file } }; diff --git a/test.toml b/test.toml new file mode 100644 index 0000000..bb62980 --- /dev/null +++ b/test.toml @@ -0,0 +1,109 @@ +[config] +work_dir = "/mnt/hdd/media/Media/Music/Library" + +[tool.bash] +env.TARGET = "/home/mark/out" + +before = """ +rm -drf ${TARGET} +""" + +script.mp3 = """ +mkdir -p "$(dirname "${TARGET}/${PICK_RELATIVE}")" + +filename="${PICK_RELATIVE%.*}" + +ffmpeg \ + -i "${PICK_FILE}" \ + -map_metadata 0 \ + -id3v2_version 3 \ + -b:a 192k \ + -loglevel error \ + -hide_banner -n \ + "${TARGET}/${filename}.mp3" +""" + +script.ogg = """ +mkdir -p "$(dirname "${TARGET}/${PICK_RELATIVE}")" + +filename="${PICK_RELATIVE%.*}" + +ffmpeg \ + -i "${PICK_FILE}" \ + -c:v libtheora \ + -q:v 10 \ + -c:a libopus \ + -b:a 192k \ + -loglevel error \ + -hide_banner -n \ + "${TARGET}/${filename}.ogg" +""" + +script.raw = """ +mkdir -p "$(dirname "${TARGET}/${PICK_RELATIVE}")" +cp "${PICK_FILE}" "${TARGET}/${PICK_RELATIVE}" +""" + + +# The first rule to match a path is run. +# Paths are checked relative to source. +# "/source/path/to/file.gz" becomes "path/to/file.gz" +# +# a "path segment" is a single file or directory. +# +# * matches exactly one path segment. In regex, this is [^/]+ +# ** matches zero or more path segments. In regex, this is ([^/]+)* +# +# All rules are matched against the FULL PATH of files. +# Directories are ignored. +[[rules]] +"Classical/**" = "" +"Holiday/**" = "" +"Rock/**" = "" +"Electro-Swing/**" = "" +"Score/**" = "" +"Country/**" = "" +"Instrument/**" = "" +"Lofi Rip/**" = "raw" + + +[[rules."Ru"]] +"The Alexandrov Red Army Chorus/**" = "raw" +"Алиса/**" = "raw" +"Андрей Губин/**" = "raw" +"Баста/**" = "raw" +"Виктор Цой/**" = "raw" +"Денис Майданов/**" = "raw" +"дора/**" = "raw" +"Игорь Растеряев/**" = "raw" +"Иосиф Кобзон/**" = "raw" +"Кино/**" = "raw" +"Лев Лещенко/**" = "raw" +"Любэ/**" = "raw" +"Марк Бернес/**" = "raw" +"Муслим Магомаев/**" = "raw" +"Отава Ё/**" = "raw" +"**" = "" + +[[rules."Pop"]] +"5 Seconds Of Summer/**" = "mp3" +"Andy Grammer/**" = "raw" +"Christina Perri/**" = "raw" +"Club Danger/**" = "raw" +"Colbie Caillat/**" = "raw" +"Echosmith/**" = "raw" +"Future Royalty/**" = "raw" +"Imagine Dragons/**" = "raw" +"Kate Voegele/**" = "raw" +"NEFFEX/**" = "raw" +"NewJeans/**" = "raw" +"Niall Horan/**" = "raw" +"Of Monsters and Men/**" = "raw" +"Oh The Larceny/**" = "raw" +"OneRepublic/**" = "raw" +"Outskrts/**" = "raw" +"Paramore/**" = "raw" +"Taylor Swift/**" = "raw" +"The Score/**" = "raw" +"The Seige/**" = "raw" +"**" = ""