feat: add verbose log
This commit is contained in:
+18
-5
@@ -3,7 +3,6 @@ use lofty::file::TaggedFileExt;
|
|||||||
use lofty::probe::Probe;
|
use lofty::probe::Probe;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs::read_dir;
|
use std::fs::read_dir;
|
||||||
use std::io;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod move_files;
|
mod move_files;
|
||||||
@@ -61,16 +60,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let tag = get_metadata(&path);
|
let tag = get_metadata(&path);
|
||||||
|
|
||||||
if let Err(e) =
|
if let Err(e) = move_files(
|
||||||
move_files(path.clone(), tag?, &extra_files, *copy, true, *new)
|
path.clone(),
|
||||||
{
|
tag?,
|
||||||
|
&extra_files,
|
||||||
|
*copy,
|
||||||
|
file.to_path_buf(),
|
||||||
|
true,
|
||||||
|
*new,
|
||||||
|
) {
|
||||||
eprintln!("Failed to import {:?}: {}", path, e);
|
eprintln!("Failed to import {:?}: {}", path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Importing file: {:?}", file);
|
println!("Importing file: {:?}", file);
|
||||||
let tag = get_metadata(file);
|
let tag = get_metadata(file);
|
||||||
move_files(file.clone(), tag?.clone(), &extra_files, *copy, false, *new)?;
|
move_files(
|
||||||
|
file.clone(),
|
||||||
|
tag?.clone(),
|
||||||
|
&extra_files,
|
||||||
|
*copy,
|
||||||
|
file.to_path_buf(),
|
||||||
|
false,
|
||||||
|
*new,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-12
@@ -5,7 +5,7 @@ use lofty::tag::Accessor;
|
|||||||
use lofty::tag::Tag;
|
use lofty::tag::Tag;
|
||||||
use std::env::var;
|
use std::env::var;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::fs::{copy, create_dir, create_dir_all, remove_dir, rename};
|
use std::fs::{File, copy, create_dir, create_dir_all, remove_dir, rename};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ pub fn move_files(
|
|||||||
tag: Tag,
|
tag: Tag,
|
||||||
extra_files: &[String],
|
extra_files: &[String],
|
||||||
should_copy: bool,
|
should_copy: bool,
|
||||||
|
folder_path: PathBuf,
|
||||||
has_parent: bool,
|
has_parent: bool,
|
||||||
add_new_playlist: bool,
|
add_new_playlist: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -89,7 +90,13 @@ pub fn move_files(
|
|||||||
remove_dir(file_path.parent().unwrap())?;
|
remove_dir(file_path.parent().unwrap())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_log(file_path)?;
|
let home_dir: PathBuf = PathBuf::from(var("HOME").expect("HOME is not set"));
|
||||||
|
let data_dir = home_dir.join(".local").join("share").join("music-sort");
|
||||||
|
let log_file_path = data_dir.join("verbose.log");
|
||||||
|
write_log(file_path.clone(), log_file_path, data_dir.clone())?;
|
||||||
|
|
||||||
|
let log_file_path = data_dir.join("music-sort.log");
|
||||||
|
write_log(folder_path, log_file_path, data_dir)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -112,20 +119,19 @@ fn new_playlist(path: PathBuf) -> std::result::Result<(), std::io::Error> {
|
|||||||
writeln!(new_playlist, "{}", path.display())
|
writeln!(new_playlist, "{}", path.display())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_log(file_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
|
fn write_log(
|
||||||
let home_dir: PathBuf = PathBuf::from(var("HOME").expect("HOME is not set"));
|
file_path: PathBuf,
|
||||||
let data_dir = home_dir.join(".local").join("share").join("music-sort");
|
log_path: PathBuf,
|
||||||
let log_file_path = data_dir.join("music-sort.log");
|
data_dir: PathBuf,
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if !data_dir.exists() {
|
if !data_dir.exists() {
|
||||||
create_dir(&data_dir)?;
|
create_dir(&data_dir)?;
|
||||||
}
|
}
|
||||||
|
if !log_path.exists() {
|
||||||
|
File::create(&log_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut log_file = OpenOptions::new()
|
let mut log_file = OpenOptions::new().append(true).open(log_path).unwrap();
|
||||||
.append(true)
|
|
||||||
.create(true)
|
|
||||||
.open(log_file_path)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Err(e) = writeln!(
|
if let Err(e) = writeln!(
|
||||||
log_file,
|
log_file,
|
||||||
|
|||||||
Reference in New Issue
Block a user