diff --git a/src/load.rs b/src/load.rs index c50dff8..c40af79 100644 --- a/src/load.rs +++ b/src/load.rs @@ -8,8 +8,8 @@ use crate::{ scan::{ArchiveMap, ManifestInfo}, }; -use anyhow::{Context, Result}; -use log::{info, warn}; +use anyhow::{bail, Context, Result}; +use log::{error, info, warn}; use neo4rs::Graph; /// takes all the archives from a map, and tries to load them sequentially @@ -74,7 +74,10 @@ pub async fn try_load_one_archive( crate::scan::BundleContent::Unknown => todo!(), crate::scan::BundleContent::StateSnapshot => { let snaps = match man.version { - crate::scan::FrameworkVersion::Unknown => todo!(), + crate::scan::FrameworkVersion::Unknown => { + error!("no framework version detected"); + bail!("could not load archive from manifest"); + } crate::scan::FrameworkVersion::V5 => extract_v5_snapshot(&man.archive_dir).await?, crate::scan::FrameworkVersion::V6 => { extract_current_snapshot(&man.archive_dir).await? diff --git a/src/scan.rs b/src/scan.rs index c9cb407..bd1844d 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -36,10 +36,13 @@ impl ManifestInfo { match self.contents { BundleContent::Unknown => return FrameworkVersion::Unknown, BundleContent::StateSnapshot => { + let man_path = self.archive_dir.join(self.contents.filename()); + dbg!(&man_path); + // first check if the v7 manifest will parse - if load_snapshot_manifest(&self.archive_dir).is_ok() { + if let Ok(_bak) = load_snapshot_manifest(&man_path) { self.version = FrameworkVersion::V7; - } + }; if v5_read_from_snapshot_manifest(&self.archive_dir).is_ok() { self.version = FrameworkVersion::V5; @@ -98,15 +101,19 @@ pub fn scan_dir_archive( ) -> Result { let path = parent_dir.canonicalize()?; let filename = content_opt.unwrap_or(BundleContent::Unknown).filename(); + dbg!(&filename); let pattern = format!( "{}/**/{}", path.to_str().context("cannot parse starting dir")?, filename, ); + dbg!(&pattern); + let mut archive = BTreeMap::new(); for entry in glob(&pattern)? { + dbg!(&entry); match entry { Ok(manifest_path) => { let dir = manifest_path @@ -114,6 +121,7 @@ pub fn scan_dir_archive( .context("no parent dir found")? .to_owned(); let contents = test_content(&manifest_path); + dbg!(&contents); let archive_id = dir.file_name().unwrap().to_str().unwrap().to_owned(); let mut m = ManifestInfo { archive_dir: dir.clone(), diff --git a/src/warehouse_cli.rs b/src/warehouse_cli.rs index fe1e220..c0114a7 100644 --- a/src/warehouse_cli.rs +++ b/src/warehouse_cli.rs @@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use clap::{Parser, Subcommand}; -use log::{info, warn}; +use log::{error, info, warn}; use neo4rs::Graph; use serde_json::json; use std::path::PathBuf; @@ -129,29 +129,25 @@ impl WarehouseCli { Sub::LoadOne { archive_dir, batch_size, - } => match scan_dir_archive(archive_dir, None)?.0.get(archive_dir) { - Some(man) => { + } => { + let am = scan_dir_archive(archive_dir, None)?; + if am.0.is_empty() { + error!("cannot find .manifest file under {}", archive_dir.display()); + } + for (_p, man) in am.0 { let pool = try_db_connection_pool(self).await?; neo4j_init::maybe_create_indexes(&pool).await?; - try_load_one_archive(man, &pool, batch_size.unwrap_or(250)).await?; - } - None => { - bail!(format!( - "ERROR: cannot find .manifest file under {}", - archive_dir.display() - )); + try_load_one_archive(&man, &pool, batch_size.unwrap_or(250)).await?; } - }, + } Sub::Check { archive_dir } => { - match scan_dir_archive(archive_dir, None)?.0.get(archive_dir) { - Some(_) => todo!(), - None => { - bail!(format!( - "ERROR: cannot find .manifest file under {}", - archive_dir.display() - )); - } + let am = scan_dir_archive(archive_dir, None)?; + if am.0.is_empty() { + error!("cannot find .manifest file under {}", archive_dir.display()); + } + for (p, man) in am.0 { + info!("manifest found at {} \n {:?}", p.display(), man); } } Sub::EnrichExchange { diff --git a/tests/test_load_state.rs b/tests/test_load_state.rs index 3d8b1a9..2d32694 100644 --- a/tests/test_load_state.rs +++ b/tests/test_load_state.rs @@ -40,7 +40,7 @@ async fn test_snapshot_batch() -> anyhow::Result<()> { libra_forensic_db::log_setup(); let archive_path = v7_state_manifest_fixtures_path(); assert!(archive_path.exists()); - let vec_snap = extract_current_snapshot(&archive_path ).await?; + let vec_snap = extract_current_snapshot(&archive_path).await?; let c = start_neo4j_container(); let port = c.get_host_port_ipv4(7687);