Make sure version increases on save
This commit is contained in:
parent
7d44a998c9
commit
59c6c5465b
3 changed files with 25 additions and 4 deletions
|
@ -39,7 +39,7 @@ impl Index {
|
|||
let index = Index::load_from_file(&Index::index_file_path_for_repository_path(&self.index_directory()?))?;
|
||||
self.merge_items_by_file_id(index.items_by_file_id);
|
||||
self.merge_newest_items(index.newest_items_by_source_path);
|
||||
self.version = max(self.version.clone(), index.version);
|
||||
self.version = max(self.version, index.version);
|
||||
}
|
||||
self.version = self.version.next();
|
||||
self.write_index_to_file(self.index_file_path())?;
|
||||
|
@ -112,3 +112,24 @@ impl Index {
|
|||
.to_path_buf())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod must {
|
||||
use crate::index::Index;
|
||||
use anyhow::Result;
|
||||
|
||||
#[test]
|
||||
fn have_version_increased_when_saved() -> Result<()> {
|
||||
let temp_dir = tempfile::tempdir()?;
|
||||
let mut index = Index::new(&temp_dir.into_path());
|
||||
let old_version = index.version;
|
||||
|
||||
index.save()?;
|
||||
|
||||
let new_version = index.version;
|
||||
|
||||
assert!(new_version > old_version);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ impl IndexItem {
|
|||
}
|
||||
|
||||
pub fn version(&self) -> Version {
|
||||
self.version.clone()
|
||||
self.version
|
||||
}
|
||||
|
||||
pub fn id(&self) -> ItemId {
|
||||
|
@ -53,7 +53,7 @@ impl From<RepositoryItem> for IndexItem {
|
|||
relative_path: i.relative_path().to_string_lossy().to_string(),
|
||||
original_source_path: i.original_source_path().to_string_lossy().to_string(),
|
||||
id: i.id().clone(),
|
||||
version: i.version().clone(),
|
||||
version: *i.version(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Serialize, Deserialize, Hash)]
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Serialize, Deserialize, Hash)]
|
||||
pub struct Version(u128);
|
||||
|
||||
impl Version {
|
||||
|
|
Loading…
Reference in a new issue