2024-11-17 22:34:43 +01:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2024-11-26 20:55:49 +01:00
|
|
|
use tracing::instrument;
|
|
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
use super::{entries, Dir, DynDir, Entries, Query, VPath, VPathBuf};
|
2024-11-17 22:34:43 +01:00
|
|
|
|
|
|
|
|
pub struct Overlay {
|
|
|
|
|
base: DynDir,
|
|
|
|
|
overlay: DynDir,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Overlay {
|
|
|
|
|
pub fn new(base: DynDir, overlay: DynDir) -> Self {
|
|
|
|
|
Self { base, overlay }
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 20:55:49 +01:00
|
|
|
#[instrument("Overlay::dir", skip(self))]
|
2024-11-29 20:03:32 +01:00
|
|
|
fn dir(&self, path: &VPath) -> Vec<VPathBuf> {
|
|
|
|
|
let mut dir = entries(&self.base, path);
|
|
|
|
|
dir.append(&mut entries(&self.overlay, path));
|
2024-11-17 22:34:43 +01:00
|
|
|
dir.sort();
|
|
|
|
|
dir.dedup();
|
|
|
|
|
dir
|
|
|
|
|
}
|
2024-11-29 20:03:32 +01:00
|
|
|
}
|
2024-11-17 22:34:43 +01:00
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
impl Dir for Overlay {
|
|
|
|
|
fn query(&self, path: &VPath, query: &mut Query) {
|
|
|
|
|
query.provide(|| Entries(self.dir(path)));
|
2024-11-17 22:34:43 +01:00
|
|
|
|
2024-11-29 20:03:32 +01:00
|
|
|
self.overlay.query(path, query);
|
|
|
|
|
self.base.query(path, query);
|
2024-11-17 22:34:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Debug for Overlay {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
write!(f, "Overlay({:?}, {:?})", self.base, self.overlay)
|
|
|
|
|
}
|
|
|
|
|
}
|