use super::ConflictIndex;
use crate::{LayerIndex, SourceKind, SourceMeta};
use std::path::{Path, PathBuf};
impl ConflictIndex {
fn paths_from_archive(path: &Path) -> Vec<PathBuf> {
crate::archives::open_archive(path)
.as_deref()
.map(crate::archives::archive_paths)
.unwrap_or_default()
}
pub fn from_directories_with_archives(
dirs: impl IntoIterator<Item = impl AsRef<Path> + Sync>,
archive_paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self {
let archive_sources: Vec<(SourceMeta, Vec<PathBuf>)> = archive_paths
.into_iter()
.map(|p| {
let p = p.as_ref().to_path_buf();
let files = Self::paths_from_archive(&p);
(
SourceMeta {
path: p,
kind: SourceKind::Archive,
},
files,
)
})
.collect();
let dir_sources: Vec<(SourceMeta, Vec<PathBuf>)> = dirs
.into_iter()
.map(|d| {
let d = d.as_ref().to_path_buf();
let files = Self::walk_dir(&d);
(
SourceMeta {
path: d,
kind: SourceKind::LooseDir,
},
files,
)
})
.collect();
let layer = LayerIndex::from_file_lists(archive_sources.into_iter().chain(dir_sources));
Self::from_layer_index(&layer)
}
}