revisionstore: don't allow loading non-v1 historypacks

Summary:
v0 history packs require more complicated and slow logic for looking up
a node.  Instead of complicating our rust implementation, let's just not support
v0.

Reviewed By: quark-zju

Differential Revision: D9373395

fbshipit-source-id: 6d28a3684966b55a617619e3cae765b2944919a0
This commit is contained in:
Durham Goode 2018-08-17 09:29:49 -07:00 committed by Facebook Github Bot
parent fde91df5b7
commit 6dfc0351f4

View File

@ -172,6 +172,10 @@ impl HistoryPack {
let mmap = unsafe { MmapOptions::new().len(len as usize).map(&file)? };
let version = HistoryPackVersion::new(mmap[0])?;
if version != HistoryPackVersion::One {
return Err(HistoryPackError(format!("version {:?} not supported", version)).into());
}
let index_path = path.with_extension("histidx");
Ok(HistoryPack {
mmap: mmap,
@ -340,6 +344,7 @@ mod tests {
use rand::SeedableRng;
use rand::chacha::ChaChaRng;
use std::collections::HashMap;
use std::fs::{File, OpenOptions};
use tempfile::TempDir;
use mutablehistorypack::MutableHistoryPack;
@ -477,6 +482,37 @@ mod tests {
assert_eq!(iter_keys, keys,);
}
#[test]
fn test_open_v0() {
let mut rng = ChaChaRng::from_seed([0u8; 32]);
let tempdir = TempDir::new().unwrap();
let (nodes, ancestors) = get_nodes(&mut rng);
let mut mutpack = MutableHistoryPack::new(tempdir.path(), HistoryPackVersion::One).unwrap();
for (ref key, ref info) in nodes.iter() {
mutpack.add(key.clone(), info.clone()).unwrap();
}
let path = mutpack.close().unwrap();
let pack_path = path.with_extension("histpack");
let mut buf = Vec::new();
{
let mut file = File::open(&pack_path).unwrap();
file.read_to_end(&mut buf).unwrap();
}
buf[0] = 0;
OpenOptions::new()
.write(true)
.open(&pack_path)
.unwrap()
.write_all(&buf)
.unwrap();
assert!(HistoryPack::new(&pack_path).is_err());
}
quickcheck! {
fn test_file_section_header_serialization(name: Vec<u8>, count: u32) -> bool {
let header = FileSectionHeader {