Only copy cached index from root if it does not exist locally

This commit is contained in:
Travis Burtrum 2022-08-07 23:20:42 -04:00
parent 0ddbc9dace
commit d2c3cffb6e
1 changed files with 8 additions and 4 deletions

View File

@ -109,15 +109,19 @@ impl Debug for FileTree {
impl FileTree {
fn load_or_build(root_path: &Path, cache_path: &Path) -> SerdeResult<Self> {
let root_index = root_path.join(INDEX_NAME);
let path = cache_path.join(INDEX_NAME);
if root_index.exists() {
std::fs::copy(&root_index, &path)?;
}
match FileTree::load(&path) {
Ok(tree) => return Ok(tree),
Err(e) => warn!("error loading {:?}: {:?}", path, e),
}
let root_index = root_path.join(INDEX_NAME);
if root_index.exists() {
std::fs::copy(&root_index, &path)?;
match FileTree::load(&path) {
Ok(tree) => return Ok(tree),
Err(e) => warn!("error loading {:?}: {:?}", path, e),
}
}
let tree = FileTree::build(root_path);
tree.save(&path)?;
Ok(tree)