mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
mutabledatapack: write version number header
Summary: The mutabledatapack format has a one byte header containing the version number. Reviewed By: quark-zju Differential Revision: D8305653 fbshipit-source-id: c4a96dc48e64acd2c5849034e5d90b87363fbc8d
This commit is contained in:
parent
99a11bbb24
commit
4588cc18c8
@ -12,7 +12,7 @@ use tempfile::NamedTempFile;
|
||||
use error::Result;
|
||||
|
||||
pub struct MutableDataPack {
|
||||
version: u32,
|
||||
version: u8,
|
||||
dir: PathBuf,
|
||||
data_file: NamedTempFile,
|
||||
hasher: Sha1,
|
||||
@ -29,7 +29,7 @@ impl MutableDataPack {
|
||||
/// when close() is called, at which point the MutableDataPack is consumed. If
|
||||
/// close() is not called, the temporary file is cleaned up when the object is
|
||||
/// release.
|
||||
pub fn new(dir: &Path, version: u32) -> Result<Self> {
|
||||
pub fn new(dir: &Path, version: u8) -> Result<Self> {
|
||||
if !dir.is_dir() {
|
||||
return Err(format_err!(
|
||||
"cannot create mutable datapack in non-directory '{:?}'",
|
||||
@ -37,13 +37,16 @@ impl MutableDataPack {
|
||||
));
|
||||
}
|
||||
|
||||
let data_file = NamedTempFile::new_in(&dir)?;
|
||||
let mut data_file = NamedTempFile::new_in(&dir)?;
|
||||
let mut hasher = Sha1::new();
|
||||
data_file.write_u8(version)?;
|
||||
hasher.input(&[version]);
|
||||
|
||||
Ok(MutableDataPack {
|
||||
version: version,
|
||||
dir: dir.to_path_buf(),
|
||||
data_file: data_file,
|
||||
hasher: Sha1::new(),
|
||||
hasher: hasher,
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user