mirror of
https://github.com/facebook/sapling.git
synced 2024-12-29 08:02:24 +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,
|
cell::RefCell,
|
||||||
collections::vec_deque::{Iter, IterMut},
|
collections::vec_deque::{Iter, IterMut},
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
fs::read_dir,
|
fs::{read_dir, DirEntry},
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{
|
sync::{
|
||||||
@ -235,34 +235,42 @@ impl<T: LocalStore + Repackable + StoreFromPath> PackStoreInner<T> {
|
|||||||
fn rescan(&self) -> Result<()> {
|
fn rescan(&self) -> Result<()> {
|
||||||
let mut new_packs = Vec::new();
|
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) {
|
let readdir = match read_dir(&self.pack_dir) {
|
||||||
Ok(readdir) => readdir,
|
Ok(readdir) => readdir,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.kind() == ErrorKind::NotFound {
|
if e.kind() == ErrorKind::NotFound {
|
||||||
return Ok(());
|
return Ok(vec![]);
|
||||||
} else {
|
} else {
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut result = vec![];
|
||||||
for entry in readdir {
|
for entry in readdir {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
if entry.file_type()?.is_file() {
|
if entry.file_type()?.is_file() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if let Some(ext) = path.extension() {
|
if let Some(ext) = path.extension() {
|
||||||
if ext == self.extension {
|
if ext == self.extension {
|
||||||
if let Ok(pack) = T::from_path(&path) {
|
result.push(entry);
|
||||||
new_packs.push(pack);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.packs.replace(new_packs.into());
|
Ok(result)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scan the store when too much time has passed since the last scan. Returns whether the
|
/// Scan the store when too much time has passed since the last scan. Returns whether the
|
||||||
|
Loading…
Reference in New Issue
Block a user