mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit e4a2ea4ee1e0e966d227a02cdbcd2107c398900c
parent 0f3d7230ad75458c1b046ba8caea30611b39f6f5
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Sun, 14 Mar 2021 19:21:45 +0100

be forgiving when loading repos

Diffstat:
Msrc/main.rs | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -35,16 +35,17 @@ struct IndexTemplate<'a> { async fn index(req: Request<()>) -> tide::Result { let config = &Config::global(); - let repos = &config.repo_directory; - let paths = fs::read_dir(repos)?; - let mut index_template = IndexTemplate { - repos: vec![], - config: config, - }; // TODO replace with map/collect - for path in paths { - let repo = Repository::open(path?.path())?; - index_template.repos.push(repo); - } + let repos = fs::read_dir(&config.repo_directory) + .map(|entries| { + entries + .filter_map(|entry| Some(entry.ok()?.path())) + // TODO check for git-daemon-export-ok file + .filter_map(|entry| Repository::open(entry).ok()) + .collect::<Vec<_>>() + }) + .map_err(|e| tide::log::warn!("can not read repositories: {}", e)) + .unwrap_or_default(); + let mut index_template = IndexTemplate { repos, config }; Ok(index_template.into()) }