diff options
author | Tuomas Siipola | 2020-02-01 00:31:05 +0200 |
---|---|---|
committer | Tuomas Siipola | 2020-02-01 00:31:05 +0200 |
commit | 2290d7b7416f6d1d316d49a5df5a941fa7d0289b (patch) | |
tree | a9b52a250815bdfee605e91f0d97faac15199670 | |
parent | 45adcd19aca3b55a292b8ccef04ec4b3999a5086 (diff) |
-rw-r--r-- | src/git.rs | 10 | ||||
-rw-r--r-- | src/http.rs | 14 |
2 files changed, 13 insertions, 11 deletions
@@ -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") |