rename to lock

This commit is contained in:
Cyryl Płotnicki 2020-11-13 22:37:41 +00:00
parent 388d160a74
commit f83baa0515
2 changed files with 4 additions and 4 deletions

View file

@ -20,7 +20,7 @@ impl Index {
let mut index = Index::new(repository_path); let mut index = Index::new(repository_path);
index.save()?; index.save()?;
} }
let lock = Lock::new(repository_path)?; let lock = Lock::lock(repository_path)?;
let index = Index::load_from_file(&Index::index_file_path_for_repository_path(repository_path))?; let index = Index::load_from_file(&Index::index_file_path_for_repository_path(repository_path))?;
lock.release()?; lock.release()?;
log::debug!( log::debug!(
@ -34,7 +34,7 @@ impl Index {
pub fn save(&mut self) -> Result<()> { pub fn save(&mut self) -> Result<()> {
let lock_id = Uuid::new_v4(); let lock_id = Uuid::new_v4();
let lock = Lock::new(&self.index_directory()?)?; let lock = Lock::lock(&self.index_directory()?)?;
if self.index_file_path().exists() { if self.index_file_path().exists() {
let index = Index::load_from_file(&Index::index_file_path_for_repository_path(&self.index_directory()?))?; 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_items_by_file_id(index.items_by_file_id);

View file

@ -14,7 +14,7 @@ pub struct Lock {
} }
impl Lock { impl Lock {
pub fn new(index_directory: &Path) -> Result<Self> { pub fn lock(index_directory: &Path) -> Result<Self> {
let mut buffer = [0u8; 16]; let mut buffer = [0u8; 16];
OsRng.fill_bytes(&mut buffer); OsRng.fill_bytes(&mut buffer);
let id = Uuid::from_bytes(buffer); let id = Uuid::from_bytes(buffer);
@ -101,7 +101,7 @@ mod must {
fn be_released_when_dropped() -> Result<()> { fn be_released_when_dropped() -> Result<()> {
let temp_dir = tempfile::tempdir()?; let temp_dir = tempfile::tempdir()?;
{ {
let _lock = Lock::new(&temp_dir.path()); let _lock = Lock::lock(&temp_dir.path());
} }
let entries = fs::read_dir(temp_dir.into_path())? let entries = fs::read_dir(temp_dir.into_path())?
.map(|res| res.map(|e| e.path())) .map(|res| res.map(|e| e.path()))