From 74bfc9de4b60b1f00821edc1f643bc9087d18b33 Mon Sep 17 00:00:00 2001 From: andi Date: Sun, 21 Aug 2016 15:29:46 +0200 Subject: [PATCH] store all tracks when scanning --- src/manager.rs | 12 +++++++++--- src/models.rs | 2 ++ src/scan.rs | 11 ++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/manager.rs b/src/manager.rs index 4c0bc62..ea5a443 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -34,9 +34,15 @@ impl<'a> TrackManager<'a> { hash: hash, }; - diesel::insert(&new_track).into(track::table) - .execute(self.conn) - .expect("Error saving new track"); + match diesel::insert(&new_track).into(track::table) + .execute(self.conn) { + Err(why) => { + error!("failed saving new track: {:?}, {:?}", why, new_track); + }, + Ok(t_) => { + info!("saved new track: {:?}", t_); + } + } track_dsl.find(hash) .get_result::(self.conn) diff --git a/src/models.rs b/src/models.rs index cf85d97..5edf622 100644 --- a/src/models.rs +++ b/src/models.rs @@ -5,6 +5,7 @@ use super::schema::track; /// /// TODO amb: *attention* the `PRIMARY KEY` field must be the first in this struct /// #[column_name(something)] will not work +#[derive(Debug)] #[derive(Queryable)] pub struct Track { /// hash of the parsed file @@ -18,6 +19,7 @@ pub struct Track { } +#[derive(Debug)] #[insertable_into(track)] pub struct NewTrack<'a> { pub hash: &'a str, diff --git a/src/scan.rs b/src/scan.rs index 2dd53d9..90c42a3 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -53,13 +53,14 @@ impl<'a> Scanner<'a> { } drop(tx); for track_ in rx.iter() { - self.track_manager.create_track(&track_.path, &track_.album, &track_.title, - &track_.hash); + info!("{:?}", &track_.path); warn!("{} - {} [{}]", - Green.paint(track_.album), - Green.paint(track_.title), - track_.hash, + Green.paint(track_.album.to_owned()), + Green.paint(track_.title.to_owned()), + track_.hash.to_owned(), ); + self.track_manager.create_track(&track_.path, &track_.album, &track_.title, + &track_.hash); } }