diff --git a/src/application/parsers/rs.rs b/src/application/parsers/rs.rs index 8735498..7cd11c3 100644 --- a/src/application/parsers/rs.rs +++ b/src/application/parsers/rs.rs @@ -10,6 +10,7 @@ pub fn parse(path: &PathBuf) -> Result, String> { let mut author = Author::new(); author.first_name = path.extension().unwrap().to_string_lossy().to_string(); book.author.push(author); + book.source = path.into(); return Ok(vec![ book]); } diff --git a/src/application/services/books.rs b/src/application/services/books.rs index 3805832..36e8235 100644 --- a/src/application/services/books.rs +++ b/src/application/services/books.rs @@ -70,7 +70,10 @@ impl Books { pub fn add_books_from_path(&mut self) { let books = fs::Loader::new(PathBuf::from(&self.root)) .into_iter() - .map(|mut book| {book.source = book.source.strip_prefix(&self.root).unwrap().into(); book}) + .map(|mut book| {match book.source.strip_prefix(&self.root) { + Ok(path) => book.source = path.to_path_buf(), + Err(err) => eprintln!("strip source prefix: {}", err) + }; book}) .collect(); match self.repo.lock() {