summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/bin/adenosine-pds-import.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-10-31 17:19:29 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-10-31 17:19:29 -0700
commit7f43d097d84c4b3f9a63981c3f6a67db82046bd3 (patch)
tree82fadbbca3f291963584e3586a60ceff09b66900 /adenosine-pds/src/bin/adenosine-pds-import.rs
parentb80360a2cfe87b4e4dd24f06010642976b858f26 (diff)
downloadadenosine-7f43d097d84c4b3f9a63981c3f6a67db82046bd3.tar.gz
adenosine-7f43d097d84c4b3f9a63981c3f6a67db82046bd3.zip
pds: move earlier commands to lib and tests
Diffstat (limited to 'adenosine-pds/src/bin/adenosine-pds-import.rs')
-rw-r--r--adenosine-pds/src/bin/adenosine-pds-import.rs53
1 files changed, 0 insertions, 53 deletions
diff --git a/adenosine-pds/src/bin/adenosine-pds-import.rs b/adenosine-pds/src/bin/adenosine-pds-import.rs
deleted file mode 100644
index 37ea6eb..0000000
--- a/adenosine-pds/src/bin/adenosine-pds-import.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-/// Helper program to import an IPLD CARv1 file in to sqlite data store
-use anyhow::{anyhow, Result};
-use futures::TryStreamExt;
-use ipfs_sqlite_block_store::BlockStore;
-use iroh_car::CarReader;
-use libipld::block::Block;
-use tokio::fs::File;
-use tokio::io::BufReader;
-
-use std::env;
-
-async fn load_car_to_sqlite(db_path: &str, car_path: &str) -> Result<()> {
- let car_reader = {
- let file = File::open(car_path).await?;
- let buf_reader = BufReader::new(file);
- CarReader::new(buf_reader).await?
- };
- let car_header = car_reader.header().clone();
- let mut db: BlockStore<libipld::DefaultParams> = {
- let path = std::path::PathBuf::from(db_path);
- let path = ipfs_sqlite_block_store::DbPath::File(path);
- BlockStore::open_path(path, Default::default())?
- };
-
- car_reader
- .stream()
- .try_for_each(|(cid, raw)| {
- // TODO: error handling here instead of unwrap (?)
- let block = Block::new(cid, raw).unwrap();
- db.put_block(block, None).unwrap();
- futures::future::ready(Ok(()))
- })
- .await?;
-
- // pin the header
- if car_header.roots().len() >= 1 {
- db.alias(b"import".to_vec(), Some(&car_header.roots()[0]))?;
- }
-
- Ok(())
-}
-
-#[tokio::main]
-async fn main() -> Result<()> {
- let args: Vec<String> = env::args().collect();
- if args.len() != 3 {
- println!("expected 2 args: <db_path> <car_path>");
- std::process::exit(-1);
- }
- let db_path = &args[1];
- let car_path = &args[2];
- load_car_to_sqlite(db_path, car_path).await
-}