fix: panic if track number is none

This commit is contained in:
2026-09-04 21:07:02 +02:00
parent b0f8486209
commit 0d06183291
3 changed files with 12 additions and 9 deletions
+1
View File
@@ -1,4 +1,5 @@
/target /target
/test /test
/.direnv
*.flac *.flac
*.mp3 *.mp3
-2
View File
@@ -44,7 +44,6 @@
buildInputs = [ buildInputs = [
rust rust
cargo-nextest cargo-nextest
fish
]; ];
env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
@@ -52,7 +51,6 @@
shellHook = '' shellHook = ''
echo Entered Rust dev shell for project music-sort echo Entered Rust dev shell for project music-sort
exec fish
''; '';
}; };
}; };
+11 -7
View File
@@ -36,12 +36,16 @@ pub fn move_files(
create_dir_all(&dir_to_create)?; create_dir_all(&dir_to_create)?;
let target = target_dir.join(artist_dir).join(album_dir.as_ref()); let target = target_dir.join(artist_dir).join(album_dir.as_ref());
let file_name = PathBuf::from(format!( let file_name = if let Some(track_number) = track_number {
"0{}. {} - {}.flac", PathBuf::from(format!(
track_number.unwrap(), "{:02}. {} - {}.flac",
artist.unwrap(), track_number,
title.unwrap(), artist.unwrap(),
)); title.unwrap(),
))
} else {
PathBuf::from(format!("01. {} - {}.flac", artist.unwrap(), title.unwrap(),))
};
if should_copy { if should_copy {
copy(&file_path, target.join(file_name))?; copy(&file_path, target.join(file_name))?;
@@ -72,6 +76,6 @@ pub fn move_files(
remove_dir(file_path.parent().unwrap())?; remove_dir(file_path.parent().unwrap())?;
} }
println!("Imported file: {:?}", file_path.file_name().unwrap()); //println!("Imported file: {:?}", file_path.file_name().unwrap());
Ok(()) Ok(())
} }