diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-10-15 09:28:30 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-10-15 09:28:30 +0300 |
commit | 2e73159d4205bf7d82d802635a9cdc164f7da9db (patch) | |
tree | 8fed4a658fa22b2ea7422d4baea414e6bae0f8cb | |
parent | 5aea64a987e600fdc7094bf3624662eae9ae3f19 (diff) | |
download | riki-2e73159d4205bf7d82d802635a9cdc164f7da9db.tar.gz |
refactor: add SourceDir
Sponsored-by: author
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/srcdir.rs | 38 |
2 files changed, 39 insertions, 0 deletions
@@ -7,6 +7,7 @@ //! little slow. This care implements a subset of the functionality of //! ikiwiki in Rust, for speed. +pub mod srcdir; pub mod name; pub mod directive; pub mod error; diff --git a/src/srcdir.rs b/src/srcdir.rs new file mode 100644 index 0000000..f8d3949 --- /dev/null +++ b/src/srcdir.rs @@ -0,0 +1,38 @@ +use crate::error::SiteError; +use log::trace; +use std::path::{Path, PathBuf}; +use walkdir::WalkDir; + +pub struct SouceDir { + path: PathBuf, + files: Vec<PathBuf>, +} + +impl SouceDir { + pub fn new(path: &Path) -> Self { + Self { + path: path.into(), + files: vec![], + } + } + + pub fn insert(&mut self, path: &Path) { + trace!("Source Dir::insert: path={}", path.display()); + self.files.push(path.into()); + } + + pub fn scan(&mut self) -> Result<(), SiteError> { + trace!("SourceDir::scan: find files in {}", self.path.display()); + for e in WalkDir::new(&self.path) { + let e = e.map_err(|err| SiteError::WalkDir(self.path.clone(), err))?; + let path = e.path(); + trace!("SourceDir::scan: found {}", path.display()); + self.insert(path); + } + Ok(()) + } + + pub fn files(&self) -> &[PathBuf] { + &self.files + } +} |