Use async client to check if a repo exists
This commit is contained in:
parent
c3dffac5da
commit
0128e267cc
22
src/main.rs
22
src/main.rs
@ -137,8 +137,12 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str) -> Result<(u64, String, u64)
|
|||||||
Ok((cache.count, head, commits))
|
Ok((cache.count, head, commits))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remote_exists(url: &str) -> Result<bool> {
|
fn remote_exists(url: &str) -> impl Future<Item = bool, Error = Error> {
|
||||||
Ok(CLIENT.head(url).send()?.status() == reqwest::StatusCode::OK)
|
CLIENT
|
||||||
|
.head(url)
|
||||||
|
.send()
|
||||||
|
.map(|resp| resp.status() == reqwest::StatusCode::OK)
|
||||||
|
.from_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HocResult {
|
enum HocResult {
|
||||||
@ -163,15 +167,15 @@ where
|
|||||||
T: Service,
|
T: Service,
|
||||||
F: Fn(HocResult) -> Result<HttpResponse>,
|
F: Fn(HocResult) -> Result<HttpResponse>,
|
||||||
{
|
{
|
||||||
futures::future::result(Ok(()))
|
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
||||||
.and_then(move |_| {
|
let service_path = format!("{}/{}", T::domain(), repo);
|
||||||
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
|
let path = format!("{}/{}", state.repos, service_path);
|
||||||
let service_path = format!("{}/{}", T::domain(), repo);
|
let url = format!("https://{}", service_path);
|
||||||
let path = format!("{}/{}", state.repos, service_path);
|
remote_exists(&url)
|
||||||
|
.and_then(move |remote_exists| {
|
||||||
let file = Path::new(&path);
|
let file = Path::new(&path);
|
||||||
let url = format!("https://{}", service_path);
|
|
||||||
if !file.exists() {
|
if !file.exists() {
|
||||||
if !remote_exists(&url)? {
|
if !remote_exists {
|
||||||
warn!("Repository does not exist: {}", url);
|
warn!("Repository does not exist: {}", url);
|
||||||
return Ok(HocResult::NotFound);
|
return Ok(HocResult::NotFound);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user