aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/git.rs10
-rw-r--r--src/http.rs14
2 files changed, 13 insertions, 11 deletions
diff --git a/src/git.rs b/src/git.rs
index 4c457d0..457e460 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -130,8 +130,8 @@ impl Repository {
pub fn walk_tree(
&self,
tree: &git2::Tree,
- callback: &mut impl FnMut(&[u8], &git2::TreeEntry) -> (),
- ) -> Result<(), git2::Error> {
+ callback: &mut impl FnMut(&[u8], &git2::TreeEntry) -> Result<(), Box<dyn std::error::Error>>,
+ ) -> Result<(), Box<dyn std::error::Error>> {
walk_tree(&self.0, &tree, &mut Vec::new(), callback)
}
}
@@ -141,8 +141,8 @@ fn walk_tree(
repo: &git2::Repository,
tree: &git2::Tree,
mut path: &mut Vec<u8>,
- callback: &mut impl FnMut(&[u8], &git2::TreeEntry) -> (),
-) -> Result<(), git2::Error> {
+ callback: &mut impl FnMut(&[u8], &git2::TreeEntry) -> Result<(), Box<dyn std::error::Error>>,
+) -> Result<(), Box<dyn std::error::Error>> {
for entry in tree {
let old_len = path.len();
path.extend_from_slice(entry.name_bytes());
@@ -152,7 +152,7 @@ fn walk_tree(
walk_tree(repo, &repo.find_tree(entry.id())?, &mut path, callback)?;
}
Some(git2::ObjectType::Blob) => {
- callback(&path, &entry);
+ callback(&path, &entry)?;
}
_ => {}
}
diff --git a/src/http.rs b/src/http.rs
index 52fe26e..8445c20 100644
--- a/src/http.rs
+++ b/src/http.rs
@@ -574,19 +574,21 @@ async fn archive(name: &[u8], rev: &[u8]) -> MyResponse {
let mut ar = tar::Builder::new(Vec::new());
repo.walk_tree(&tree, &mut |path, entry: &git2::TreeEntry| {
- let blob = repo.0.find_blob(entry.id()).unwrap();
+ let blob = repo.0.find_blob(entry.id())?;
let mut header = tar::Header::new_gnu();
- header.set_size(blob.size().try_into().unwrap());
- header.set_mode(entry.filemode().try_into().unwrap());
+ header.set_size(blob.size().try_into()?);
+ header.set_mode(entry.filemode().try_into()?);
if let Some(commit) = repo.commits(commit.id(), Some(&path)).next() {
header.set_mtime(commit.timestamp());
}
header.set_cksum();
- ar.append_data(&mut header, OsStr::from_bytes(&path), blob.content())
- .unwrap();
- })?;
+ ar.append_data(&mut header, OsStr::from_bytes(&path), blob.content())?;
+
+ Ok(())
+ })
+ .map_err(|err| MyError::ServerError(format!("failed to create archive: {}", err)))?;
Ok(Response::builder()
.header("Content-Type", "application/x-tar")