aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-11-04 16:20:48 -0700
committerBryan Newbold <bnewbold@robocracy.org>2017-11-04 16:20:48 -0700
commita2a99f18d43dbfb76f72fe2771c292b9090e21f0 (patch)
tree2d83a90871a19bbfd19b40a86ad25cc3ce7f904c
parent370b8bb96764ea71f52650440a60a4cabc7bcf63 (diff)
downloadgeniza-a2a99f18d43dbfb76f72fe2771c292b9090e21f0.tar.gz
geniza-a2a99f18d43dbfb76f72fe2771c292b9090e21f0.zip
add drive-level verification
-rw-r--r--src/bin/geniza-drive.rs21
-rw-r--r--src/drive.rs24
2 files changed, 32 insertions, 13 deletions
diff --git a/src/bin/geniza-drive.rs b/src/bin/geniza-drive.rs
index dae8294..32104e4 100644
--- a/src/bin/geniza-drive.rs
+++ b/src/bin/geniza-drive.rs
@@ -1,7 +1,6 @@
// Free Software under GPL-3.0, see LICENSE
// Copyright 2017 Bryan Newbold
-#[macro_use]
extern crate clap;
extern crate env_logger;
#[macro_use]
@@ -34,20 +33,12 @@ fn run() -> Result<()> {
SubCommand::with_name("log")
.about("History of additions/deletions from this dat")
)
+ .subcommand(
+ SubCommand::with_name("verify")
+ .about("Checks signatures et al")
+ )
.get_matches();
-/*
- mode: ::std::option::Option<u32>,
- uid: ::std::option::Option<u32>,
- gid: ::std::option::Option<u32>,
- size: ::std::option::Option<u64>,
- blocks: ::std::option::Option<u64>,
- offset: ::std::option::Option<u64>,
- byteOffset: ::std::option::Option<u64>,
- mtime: ::std::option::Option<u64>,
- ctime: ::std::option::Option<u64>,
-*/
-
let dir = Path::new(matches.value_of("dat-dir").unwrap());
match matches.subcommand() {
("ls", Some(_subm)) => {
@@ -75,6 +66,10 @@ fn run() -> Result<()> {
}
}
}
+ ("verify", Some(_subm)) => {
+ let mut drive = DatDrive::open(dir, false)?;
+ println!("{:?}", drive.verify());
+ }
_ => {
println!("Missing or unimplemented command!");
println!("{}", matches.usage());
diff --git a/src/drive.rs b/src/drive.rs
index 9826980..73c0744 100644
--- a/src/drive.rs
+++ b/src/drive.rs
@@ -152,6 +152,30 @@ impl<'a> DatDrive {
unimplemented!()
}
+ pub fn read_file_bytes<P: AsRef<Path>, R: Read>(&mut self, path: P) -> Result<Vec<u8>> {
+ let de = self.broken_find_file(path.as_ref())?;
+ if let Some(entry) = de {
+ // TODO: read and concatonate chunks
+ let stat = entry.stat.unwrap();
+ let mut buf = vec![];
+ let offset = stat.get_offset();
+ let blocks = stat.get_blocks();
+ for i in offset..(offset+blocks) {
+ let mut chunk = self.content.get_data_entry(i)?;
+ buf.append(&mut chunk);
+ }
+ return Ok(buf);
+ } else {
+ bail!("Couldn't find path: {}", path.as_ref().display());
+ }
+ }
+
+ pub fn verify(&mut self) -> Result<()> {
+ self.metadata.verify()?;
+ self.content.verify()?;
+ Ok(())
+ }
+
/* Possible future helper functions to be even more like std::fs
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(&mut self, from: P, to: Q) -> Result<()>
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(&mut self, from: P, to: Q) -> Result<()>