mygit

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

commit c6315c2682da8bdfc8048739339f0dc125cee675
parent 92fb691411f904598a08986e0ab910ed4de737b7
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Wed, 31 Mar 2021 19:06:24 +0200

deduplicate error message

Diffstat:
Msrc/main.rs | 19++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -145,23 +145,12 @@ fn repo_from_request(repo_name: &str) -> Result<Repository, tide::Error> { )); } - let repo = Repository::open(repo_path).or_else(|_| { - Err(tide::Error::from_str( - 404, - "This repository does not exist.", - )) - })?; - - if !repo.path().join(&CONFIG.export_ok).exists() { + Repository::open(repo_path) + .ok() // outside users should not be able to tell the difference between // nonexistent and existing but forbidden repos, so not using 403 - Err(tide::Error::from_str( - 404, - "This repository does not exist.", - )) - } else { - Ok(repo) - } + .filter(|repo| repo.path().join(&CONFIG.export_ok).exists()) + .ok_or_else(|| tide::Error::from_str(404, "This repository does not exist.")) } async fn repo_home(req: Request<()>) -> tide::Result {