Skip to content

Commit

Permalink
wip scanning dir for manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 8, 2024
1 parent 1bcb815 commit d239522
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions warehouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ version.workspace = true
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
glob = { workspace = true }
tokio ={ workspace = true }
1 change: 1 addition & 0 deletions warehouse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod warehouse_cli;
pub mod scan;
43 changes: 43 additions & 0 deletions warehouse/src/scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! scan
use anyhow::{Context, Result};
use glob::glob;
use std::{collections::BTreeMap, path::{Path, PathBuf}};
pub struct ArchiveMap(BTreeMap<PathBuf, ManifestInfo>);
pub struct ManifestInfo {
/// the enclosing directory of the .manifest file
dir: PathBuf,
/// what libra version were these files encoded with (v5 etc)
version: EncodingVersion,
/// contents of the manifest
contents: BundleContent,
/// processed
processed: bool,
}

enum EncodingVersion {
V5,
V6,
V7,
}

enum BundleContent {
Snapshot,
Transactions,
Epoch,
}

/// Crawl a directory and find all .manifest files
pub fn scan_dir_archive(start_dir: &Path) -> Result<ArchiveMap>{
let path = start_dir.canonicalize()?;

let pattern = format!("{}/**/*.manifest", path.to_str().context("cannot parse starting dir")?);

for entry in glob(&pattern).expect("Failed to read glob pattern") {
match entry {
Ok(path) => println!("{:?}", path.display()),
Err(e) => println!("{:?}", e),
}
}
let mut a = BTreeMap::new();
Ok(ArchiveMap(a))
}
2 changes: 1 addition & 1 deletion warehouse/src/warehouse_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Result};

use clap::{Parser, Subcommand};
use std::{fs, path::PathBuf};

Expand Down
11 changes: 11 additions & 0 deletions warehouse/tests/scan_dirs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::path::Path;

#[test]

fn test_scan_dir_for_manifests() {
let p = Path::from(env!("CARGO_MANIFEST_DIR"));
let project_root = p.parent();
let scan_this = project_root.join("compatibility/fixtures");

let s = scan_dir_archive(scan_this);
}

0 comments on commit d239522

Please sign in to comment.