diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-12-11 23:54:26 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-12-11 23:54:26 -0800 |
commit | 66bf3345a944e087cf8b66a2fbbceb143873c5e4 (patch) | |
tree | a5c1094d0c058da5e3c078e415e69e5b14fc8289 | |
parent | 962c1b8c946e1730e2172984328d051e7b0f72de (diff) | |
download | geniza-66bf3345a944e087cf8b66a2fbbceb143873c5e4.tar.gz geniza-66bf3345a944e087cf8b66a2fbbceb143873c5e4.zip |
copy in 'geniza log' implementation
-rw-r--r-- | src/bin/geniza.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/bin/geniza.rs b/src/bin/geniza.rs index 794d3ed..f5c73b0 100644 --- a/src/bin/geniza.rs +++ b/src/bin/geniza.rs @@ -9,8 +9,26 @@ extern crate geniza; // TODO: more careful import use geniza::*; -use std::path::Path; +use std::path::{Path, PathBuf}; use clap::{App, SubCommand}; +use std::env::current_dir; + + +// Helper to find a dat directory somewhere in the parent to the current working directory (or None +// if not found) +fn find_dat_dir() -> Option<PathBuf> { + let mut here: &Path = ¤t_dir().unwrap(); + loop { + let check = here.join(".dat"); + if check.is_dir() && check.join("metadata.tree").is_file() { + return Some(check); + }; + here = match here.parent() { + None => return None, + Some(t) => t, + } + } +} fn run() -> Result<()> { env_logger::init().unwrap(); @@ -86,7 +104,31 @@ fn run() -> Result<()> { unimplemented!(); } ("log", Some(_subm)) => { - unimplemented!(); + let dat_dir = match find_dat_dir() { + Some(p) => p, + None => { + println!("Couldn't find '.dat/' in the current or (any parent) directory."); + println!("Are you running from inside a Dat archive?"); + ::std::process::exit(-1); + } + }; + println!("{:?}", dat_dir); + let mut drive = DatDrive::open(dat_dir, false)?; + for entry in drive.history(0) { + 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()); + } + } } ("checkout", Some(subm)) => { let _path = Path::new(subm.value_of("path").unwrap()); |