use std::collections::HashSet;
use std::path::{Path, PathBuf};
use mcvm_shared::UpdateDepth;
#[derive(Debug)]
pub struct UpdateManager {
pub(crate) update_depth: UpdateDepth,
files: HashSet<PathBuf>,
}
impl UpdateManager {
pub fn new(depth: UpdateDepth) -> Self {
Self {
update_depth: depth,
files: HashSet::new(),
}
}
pub fn add_file(&mut self, file: PathBuf) {
self.files.insert(file);
}
pub fn add_files(&mut self, files: HashSet<PathBuf>) {
self.files.extend(files);
}
pub fn add_result(&mut self, result: UpdateMethodResult) {
self.add_files(result.files_updated);
}
pub fn should_update_file(&self, file: &Path) -> bool {
if self.update_depth == UpdateDepth::Force {
!self.files.contains(file) || !file.exists()
} else {
!file.exists()
}
}
pub fn get_depth(&self) -> UpdateDepth {
self.update_depth
}
}
#[derive(Default)]
pub struct UpdateMethodResult {
pub files_updated: HashSet<PathBuf>,
}
impl UpdateMethodResult {
pub fn new() -> Self {
Self::default()
}
pub fn merge(&mut self, other: Self) {
self.files_updated.extend(other.files_updated);
}
}