diff options
-rw-r--r-- | src/bin/geniza-drive.rs | 14 | ||||
-rw-r--r-- | src/drive.rs | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/bin/geniza-drive.rs b/src/bin/geniza-drive.rs index 05c7fb7..8e236f7 100644 --- a/src/bin/geniza-drive.rs +++ b/src/bin/geniza-drive.rs @@ -55,7 +55,19 @@ fn run() -> Result<()> { ("log", Some(_subm)) => { let mut drive = DatDrive::open(dir, false)?; for entry in drive.history(1) { - println!("{:?}", entry?); + let entry = entry?; + if let Some(stat) = entry.stat { + if stat.get_blocks() == 0 { + println!("{}\t[chg] {}", + entry.index, entry.path.display()); + } else { + println!("{}\t[put] {}\t{} bytes ({} blocks)", + entry.index, entry.path.display(), stat.get_size(), stat.get_blocks()); + } + } else { + println!("{}\t[del] {}", + entry.index, entry.path.display()); + } } } _ => { diff --git a/src/drive.rs b/src/drive.rs index 7369fb2..9c67029 100644 --- a/src/drive.rs +++ b/src/drive.rs @@ -1,6 +1,6 @@ use std::io::Read; -use std::path::Path; +use std::path::{Path, PathBuf}; //XXX: use protobuf::Message; use protobuf::parse_from_bytes; @@ -119,8 +119,9 @@ fn test_dd_create() { // TODO: unpack Node into a pub struct #[derive(Debug)] pub struct DriveEntry { - node: Node, - index: u64, + pub index: u64, + pub path: PathBuf, + pub stat: Option<Stat>, } /// Iterator over full drive history (file additions/deletions). @@ -144,9 +145,14 @@ impl<'a> Iterator for DriveHistory<'a> { Err(e) => { return Some(Err(e.into())) }, Ok(v) => v, }; + let stat = match node.has_value() { + true => Some(parse_from_bytes::<Stat>(&node.get_value()).unwrap()), + false => None, + }; let de = Ok(DriveEntry { - node, index: self.current, + path: PathBuf::from(node.get_name()), + stat: stat, }); self.current += 1; return Some(de); |