|
|
|
@ -41,12 +41,11 @@ impl Proxy { |
|
|
|
|
.or_unexpected_while("parsing url as reqwest url")? |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let base_path = match url.to_file_path() { |
|
|
|
|
Ok(path) => path, |
|
|
|
|
Err(()) => return Err(unexpected::Error::from("extracting path from url")), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let new_path = base_path.join(sub_path); |
|
|
|
|
let new_path = url |
|
|
|
|
.path() |
|
|
|
|
.parse::<std::path::PathBuf>() |
|
|
|
|
.or_unexpected_while("parsing url path")? |
|
|
|
|
.join(sub_path); |
|
|
|
|
|
|
|
|
|
url.set_path( |
|
|
|
|
new_path |
|
|
|
@ -64,7 +63,7 @@ impl Proxy { |
|
|
|
|
let (url, branch_name) = Self::deconstruct_descr(descr); |
|
|
|
|
|
|
|
|
|
let refs_url = |
|
|
|
|
Self::construct_url(url, "/info/refs").or_unexpected_while("constructing refs url")?; |
|
|
|
|
Self::construct_url(url, "info/refs").or_unexpected_while("constructing refs url")?; |
|
|
|
|
|
|
|
|
|
// when fetching refs we assume that any issue indicates that the origin itself
|
|
|
|
|
// (and therefore the URL) has some kind of issue.
|
|
|
|
@ -102,15 +101,13 @@ impl Proxy { |
|
|
|
|
&self, |
|
|
|
|
descr: &origin::Descr, |
|
|
|
|
oid: &gix_hash::ObjectId, |
|
|
|
|
) -> unexpected::Result<Option<reqwest::Response>> { |
|
|
|
|
) -> unexpected::Result<Option<util::BoxByteStream>> { |
|
|
|
|
let hex = oid.to_string(); |
|
|
|
|
let (url, _) = Self::deconstruct_descr(descr); |
|
|
|
|
|
|
|
|
|
let object_url = Self::construct_url( |
|
|
|
|
url, |
|
|
|
|
format!("/objects/{}/{}", &hex[..2], &hex[2..]).as_str(), |
|
|
|
|
) |
|
|
|
|
.or_unexpected_while("constructing refs url")?; |
|
|
|
|
let object_url = |
|
|
|
|
Self::construct_url(url, format!("objects/{}/{}", &hex[..2], &hex[2..]).as_str()) |
|
|
|
|
.or_unexpected_while("constructing refs url")?; |
|
|
|
|
|
|
|
|
|
Ok(self |
|
|
|
|
.client |
|
|
|
@ -119,7 +116,19 @@ impl Proxy { |
|
|
|
|
.await |
|
|
|
|
.or_unexpected_while("performing request")? |
|
|
|
|
.error_for_status() |
|
|
|
|
.ok()) |
|
|
|
|
.ok() |
|
|
|
|
.map(|res| { |
|
|
|
|
use async_compression::tokio::bufread::ZlibDecoder; |
|
|
|
|
use futures::stream::TryStreamExt; |
|
|
|
|
use std::io; |
|
|
|
|
|
|
|
|
|
let r = tokio_util::io::StreamReader::new( |
|
|
|
|
res.bytes_stream() |
|
|
|
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, e)), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
util::BoxByteStream::from_async_read(ZlibDecoder::new(r)) |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn get_commit_tree( |
|
|
|
@ -131,7 +140,7 @@ impl Proxy { |
|
|
|
|
.get_object(descr, commit_hash) |
|
|
|
|
.await? |
|
|
|
|
.ok_or(origin::SyncError::Unavailable)? |
|
|
|
|
.bytes() |
|
|
|
|
.read_to_end() |
|
|
|
|
.await |
|
|
|
|
.or(Err(origin::SyncError::Unavailable))?; |
|
|
|
|
|
|
|
|
@ -153,7 +162,7 @@ impl Proxy { |
|
|
|
|
.get_object(descr, tree_hash) |
|
|
|
|
.await? |
|
|
|
|
.ok_or(origin::GetFileError::Unavailable)? |
|
|
|
|
.bytes() |
|
|
|
|
.read_to_end() |
|
|
|
|
.await |
|
|
|
|
.or(Err(origin::GetFileError::Unavailable))?; |
|
|
|
|
|
|
|
|
@ -288,17 +297,10 @@ impl origin::Store for Proxy { |
|
|
|
|
.into()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let res = self |
|
|
|
|
Ok(self |
|
|
|
|
.get_object(&descr, &entry.oid) |
|
|
|
|
.await? |
|
|
|
|
.map_unexpected_while(|| format!("object for entry {:?} not found", entry))? |
|
|
|
|
.bytes_stream(); |
|
|
|
|
|
|
|
|
|
use futures::StreamExt; |
|
|
|
|
Ok(util::into_box_byte_stream(res.map(|r| { |
|
|
|
|
use std::io::{Error, ErrorKind}; |
|
|
|
|
r.map_err(|e| Error::new(ErrorKind::ConnectionAborted, e)) |
|
|
|
|
}))) |
|
|
|
|
.map_unexpected_while(|| format!("object for entry {:?} not found", entry))?) |
|
|
|
|
|
|
|
|
|
// TODO this is still not correct, as it will include the git object header
|
|
|
|
|
}) |
|
|
|
|