diff --git a/gitlab-runner/src/artifact.rs b/gitlab-runner/src/artifact.rs index 1f1d4b7..173014f 100644 --- a/gitlab-runner/src/artifact.rs +++ b/gitlab-runner/src/artifact.rs @@ -4,7 +4,7 @@ use std::{ path::Path, }; -use zip::read::ZipFile; +use zip::{read::ZipFile, result::ZipResult}; /// A file in a gitlab artifact /// @@ -35,15 +35,6 @@ impl Read for ArtifactFile<'_> { pub(crate) trait ReadSeek: Read + Seek {} impl ReadSeek for T where T: Read + Seek {} -impl From for Artifact -where - T: Send + Read + Seek + 'static, -{ - fn from(data: T) -> Self { - Artifact::new(Box::new(data)) - } -} - /// An artifact downloaded from gitlab /// /// The artifact holds a set of files which can be read out one by one @@ -52,10 +43,9 @@ pub struct Artifact { } impl Artifact { - pub(crate) fn new(data: Box) -> Self { - //let reader = std::io::Cursor::new(data); - let zip = zip::ZipArchive::new(data).unwrap(); - Self { zip } + pub(crate) fn new(data: Box) -> ZipResult { + let zip = zip::ZipArchive::new(data)?; + Ok(Self { zip }) } /// Iterator of the files names inside the artifacts diff --git a/gitlab-runner/src/client.rs b/gitlab-runner/src/client.rs index 9aa7d07..9e04b91 100644 --- a/gitlab-runner/src/client.rs +++ b/gitlab-runner/src/client.rs @@ -8,6 +8,7 @@ use std::time::Duration; use thiserror::Error; use tokio::io::{AsyncWrite, AsyncWriteExt}; use url::Url; +use zip::result::ZipError; fn deserialize_null_default<'de, D, T>(deserializer: D) -> Result where @@ -196,6 +197,8 @@ pub enum Error { Request(#[from] reqwest::Error), #[error("Failed to write to destination {0}")] WriteFailure(#[source] futures::io::Error), + #[error("Failed to parse zip file: {0}")] + ZipFile(#[from] ZipError), #[error("Empty trace")] EmptyTrace, } diff --git a/gitlab-runner/src/job.rs b/gitlab-runner/src/job.rs index 8c09be1..9842996 100644 --- a/gitlab-runner/src/job.rs +++ b/gitlab-runner/src/job.rs @@ -200,13 +200,15 @@ impl ArtifactCache { async fn get(&self, id: u64) -> Result, ClientError> { if let Some(data) = self.lookup(id) { match data { - CacheData::MemoryBacked(m) => Ok(Some(Artifact::from(std::io::Cursor::new(m)))), + CacheData::MemoryBacked(m) => { + Ok(Some(Artifact::new(Box::new(std::io::Cursor::new(m)))?)) + } CacheData::FileBacked(p) => { let f = tokio::fs::File::open(p) .await .map_err(ClientError::WriteFailure)?; // Always succeeds as no operations have been started - Ok(Some(Artifact::from(f.try_into_std().unwrap()))) + Ok(Some(Artifact::new(Box::new(f.try_into_std().unwrap()))?)) } } } else {