diff --git a/lib/src/index_store.rs b/lib/src/index_store.rs index 6d5f32033..14ba43083 100644 --- a/lib/src/index_store.rs +++ b/lib/src/index_store.rs @@ -16,7 +16,7 @@ use std::collections::{HashMap, HashSet}; use std::fs::File; use std::io; use std::io::{Read, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::Arc; use itertools::Itertools; @@ -43,18 +43,22 @@ pub struct IndexStore { } impl IndexStore { - pub fn init(dir: PathBuf) -> Self { + pub fn init(dir: &Path) -> Self { std::fs::create_dir(dir.join("operations")).unwrap(); - IndexStore { dir } + IndexStore { + dir: dir.to_owned(), + } } pub fn reinit(&self) { std::fs::remove_dir_all(self.dir.join("operations")).unwrap(); - IndexStore::init(self.dir.clone()); + IndexStore::init(&self.dir); } - pub fn load(dir: PathBuf) -> IndexStore { - IndexStore { dir } + pub fn load(dir: &Path) -> IndexStore { + IndexStore { + dir: dir.to_owned(), + } } pub fn get_index_at_op(&self, op: &Operation, store: &Arc) -> Arc { @@ -116,7 +120,7 @@ impl IndexStore { let mut index_file = File::open(index_file_path).unwrap(); ReadonlyIndex::load_from( &mut index_file, - self.dir.clone(), + self.dir.to_owned(), index_file_id_hex, commit_id_length, change_id_length, diff --git a/lib/src/repo.rs b/lib/src/repo.rs index daac3133a..f3c34620b 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -158,7 +158,7 @@ impl ReadonlyRepo { let index_path = repo_path.join("index"); fs::create_dir(&index_path).context(&index_path)?; - let index_store = Arc::new(IndexStore::init(index_path)); + let index_store = Arc::new(IndexStore::init(&index_path)); let view = View::new(root_view); Ok(Arc::new(ReadonlyRepo { @@ -471,7 +471,7 @@ impl RepoLoader { let op_store = Arc::from(store_factories.load_op_store(&repo_path.join("op_store"))?); let op_heads_store = Arc::from(store_factories.load_op_heads_store(&repo_path.join("op_heads"))?); - let index_store = Arc::new(IndexStore::load(repo_path.join("index"))); + let index_store = Arc::new(IndexStore::load(&repo_path.join("index"))); Ok(Self { repo_path: repo_path.to_path_buf(), repo_settings,