mirror of
https://github.com/facebook/sapling.git
synced 2024-12-27 23:22:02 +03:00
revisionstore: refactor pack iteration code
Summary: In a future diff we'll add logic to delete old pack files. We'll want to use this pack iteration code, so let's move it to a function. Reviewed By: quark-zju Differential Revision: D23486920 fbshipit-source-id: 5f872e946ffe816289c925dd2e03c292e29da5af
This commit is contained in:
parent
651a0690be
commit
717d10958f
@ -9,7 +9,7 @@ use std::{
|
||||
cell::RefCell,
|
||||
collections::vec_deque::{Iter, IterMut},
|
||||
collections::VecDeque,
|
||||
fs::read_dir,
|
||||
fs::{read_dir, DirEntry},
|
||||
io::ErrorKind,
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
@ -235,34 +235,42 @@ impl<T: LocalStore + Repackable + StoreFromPath> PackStoreInner<T> {
|
||||
fn rescan(&self) -> Result<()> {
|
||||
let mut new_packs = Vec::new();
|
||||
|
||||
for entry in self.get_pack_paths()?.into_iter() {
|
||||
if let Ok(pack) = T::from_path(&entry.path()) {
|
||||
new_packs.push(pack);
|
||||
}
|
||||
}
|
||||
|
||||
self.packs.replace(new_packs.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_pack_paths(&self) -> Result<Vec<DirEntry>> {
|
||||
let readdir = match read_dir(&self.pack_dir) {
|
||||
Ok(readdir) => readdir,
|
||||
Err(e) => {
|
||||
if e.kind() == ErrorKind::NotFound {
|
||||
return Ok(());
|
||||
return Ok(vec![]);
|
||||
} else {
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut result = vec![];
|
||||
for entry in readdir {
|
||||
let entry = entry?;
|
||||
if entry.file_type()?.is_file() {
|
||||
let path = entry.path();
|
||||
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == self.extension {
|
||||
if let Ok(pack) = T::from_path(&path) {
|
||||
new_packs.push(pack);
|
||||
}
|
||||
result.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.packs.replace(new_packs.into());
|
||||
Ok(())
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Scan the store when too much time has passed since the last scan. Returns whether the
|
||||
|
Loading…
Reference in New Issue
Block a user