start impl garbage collection

This commit is contained in:
Dietmar Maurer
2018-12-18 11:06:03 +01:00
parent 529de6c7a3
commit 3d5c11e5d2
4 changed files with 86 additions and 5 deletions

View File

@ -1,6 +1,6 @@
use failure::*;
use std::path::Path;
use std::path::{PathBuf, Path};
use crate::config::datastore;
use super::chunk_store::*;
@ -40,4 +40,49 @@ impl DataStore {
Ok(index)
}
pub fn list_images(&self) -> Result<Vec<PathBuf>, Error> {
let base = self.chunk_store.base_path();
let mut list = vec![];
for entry in std::fs::read_dir(base)? {
let entry = entry?;
if entry.file_type()?.is_file() {
let path = entry.path();
if let Some(ext) = path.extension() {
if ext == "idx" {
list.push(path);
}
}
}
}
Ok(list)
}
fn sweep_used_chunks(&mut self) -> Result<(), Error> {
Ok(())
}
fn mark_used_chunks(&mut self) -> Result<(), Error> {
let image_list = self.list_images()?;
for path in image_list {
let mut index = self.open_image_reader(path)?;
index.mark_used_chunks();
}
Ok(())
}
pub fn garbage_collection(&mut self) -> Result<(), Error> {
self.mark_used_chunks()?;
self.sweep_used_chunks()?;
Ok(())
}
}