diff options
-rw-r--r-- | import/src/lib.rs | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index 116a15d..015b0b4 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -8,7 +8,7 @@ pub mod infojson; pub mod tmdb; use crate::tmdb::TmdbKind; -use anyhow::{anyhow, Context, Ok}; +use anyhow::{anyhow, bail, Context, Ok}; use async_recursion::async_recursion; use futures::{executor::block_on, stream::FuturesUnordered, StreamExt}; use jellybase::{ @@ -183,6 +183,7 @@ async fn process_source( db: &Database, fed: &Federation, ) -> anyhow::Result<()> { + debug!("{id} enter"); let insert_node = move |id: &String, n: Node| -> anyhow::Result<()> { db.node_import.fetch_and_update(id, |l| { let mut l = l.unwrap_or_default(); @@ -245,13 +246,24 @@ async fn process_source( let media_path = location.path(); if media_path.is_dir() { let mut node = Node::default(); + let mut errors = Vec::new(); for f in media_path.read_dir()? { - let child_path = f?.path(); + let f = f?; + let child_path = f.path(); let inf_id = infer_id_from_path(&child_path).context("inferring child id")?; - process_source( - id.clone(), + + if &inf_id == "archive" { + continue; + } + if let Err(err) = process_source( + inf_id.clone(), ImportSource::Media { - location: AssetLocation::Media(child_path), + location: match &location { + AssetLocation::Media(p) => { + AssetLocation::Media(p.join(f.file_name())) + } + _ => bail!("non media path media"), + }, ignore_attachments, ignore_chapters, ignore_metadata, @@ -262,10 +274,16 @@ async fn process_source( fed, ) .await - .context("recursive media import")?; + .context("recursive media import") + { + errors.push(err); + } node.public.children.push(inf_id); } insert_node(&id, node)?; + if !errors.is_empty() { + bail!("errors: {errors:?}"); + } } else if media_path.is_file() { let metadata = spawn_blocking(move || { let input = @@ -337,13 +355,13 @@ async fn process_source( insert_node(&id, node)?; } else { - warn!("non file/dir import ignored") + warn!("non file/dir import ignored: {media_path:?}") } } ImportSource::Federated { host } => { let session = fed.get_session(&host).await.context("creating session")?; - import_remote(id, &host, db, &session, index_path) + import_remote(id.clone(), &host, db, &session, index_path) .await .context("federated import")? } @@ -374,6 +392,7 @@ async fn process_source( )?; } } + debug!("{id} exit"); Ok(()) } |