Use async client to check if a repo exists

This commit is contained in:
Valentin Brandl 2019-07-22 22:26:37 +02:00
parent c3dffac5da
commit 0128e267cc
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D

View File

@ -137,8 +137,12 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String, u64)
Ok((cache.count, head, commits))
}
fn remote_exists(url: &str) -> Result<bool> {
Ok(CLIENT.head(url).send()?.status() == reqwest::StatusCode::OK)
fn remote_exists(url: &str) -> impl Future<Item = bool, Error = Error> {
CLIENT
.head(url)
.send()
.map(|resp| resp.status() == reqwest::StatusCode::OK)
.from_err()
}
enum HocResult {
@ -163,15 +167,15 @@ where
T: Service,
F: Fn(HocResult) -> Result<HttpResponse>,
{
futures::future::result(Ok(()))
.and_then(move |_| {
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
let service_path = format!("{}/{}", T::domain(), repo);
let path = format!("{}/{}", state.repos, service_path);
let file = Path::new(&path);
let url = format!("https://{}", service_path);
remote_exists(&url)
.and_then(move |remote_exists| {
let file = Path::new(&path);
if !file.exists() {
if !remote_exists(&url)? {
if !remote_exists {
warn!("Repository does not exist: {}", url);
return Ok(HocResult::NotFound);
}