File tree 3 files changed +11
-16
lines changed
3 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use std::{
4
4
path:: Path ,
5
5
} ;
6
6
7
- use zip:: read:: ZipFile ;
7
+ use zip:: { read:: ZipFile , result :: ZipResult } ;
8
8
9
9
/// A file in a gitlab artifact
10
10
///
@@ -35,15 +35,6 @@ impl Read for ArtifactFile<'_> {
35
35
pub ( crate ) trait ReadSeek : Read + Seek { }
36
36
impl < T > ReadSeek for T where T : Read + Seek { }
37
37
38
- impl < T > From < T > for Artifact
39
- where
40
- T : Send + Read + Seek + ' static ,
41
- {
42
- fn from ( data : T ) -> Self {
43
- Artifact :: new ( Box :: new ( data) )
44
- }
45
- }
46
-
47
38
/// An artifact downloaded from gitlab
48
39
///
49
40
/// The artifact holds a set of files which can be read out one by one
@@ -52,10 +43,9 @@ pub struct Artifact {
52
43
}
53
44
54
45
impl Artifact {
55
- pub ( crate ) fn new ( data : Box < dyn ReadSeek + Send > ) -> Self {
56
- //let reader = std::io::Cursor::new(data);
57
- let zip = zip:: ZipArchive :: new ( data) . unwrap ( ) ;
58
- Self { zip }
46
+ pub ( crate ) fn new ( data : Box < dyn ReadSeek + Send > ) -> ZipResult < Self > {
47
+ let zip = zip:: ZipArchive :: new ( data) ?;
48
+ Ok ( Self { zip } )
59
49
}
60
50
61
51
/// Iterator of the files names inside the artifacts
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use std::time::Duration;
8
8
use thiserror:: Error ;
9
9
use tokio:: io:: { AsyncWrite , AsyncWriteExt } ;
10
10
use url:: Url ;
11
+ use zip:: result:: ZipError ;
11
12
12
13
fn deserialize_null_default < ' de , D , T > ( deserializer : D ) -> Result < T , D :: Error >
13
14
where
@@ -196,6 +197,8 @@ pub enum Error {
196
197
Request ( #[ from] reqwest:: Error ) ,
197
198
#[ error( "Failed to write to destination {0}" ) ]
198
199
WriteFailure ( #[ source] futures:: io:: Error ) ,
200
+ #[ error( "Failed to parse zip file: {0}" ) ]
201
+ ZipFile ( #[ from] ZipError ) ,
199
202
#[ error( "Empty trace" ) ]
200
203
EmptyTrace ,
201
204
}
Original file line number Diff line number Diff line change @@ -200,13 +200,15 @@ impl ArtifactCache {
200
200
async fn get ( & self , id : u64 ) -> Result < Option < Artifact > , ClientError > {
201
201
if let Some ( data) = self . lookup ( id) {
202
202
match data {
203
- CacheData :: MemoryBacked ( m) => Ok ( Some ( Artifact :: from ( std:: io:: Cursor :: new ( m) ) ) ) ,
203
+ CacheData :: MemoryBacked ( m) => {
204
+ Ok ( Some ( Artifact :: new ( Box :: new ( std:: io:: Cursor :: new ( m) ) ) ?) )
205
+ }
204
206
CacheData :: FileBacked ( p) => {
205
207
let f = tokio:: fs:: File :: open ( p)
206
208
. await
207
209
. map_err ( ClientError :: WriteFailure ) ?;
208
210
// Always succeeds as no operations have been started
209
- Ok ( Some ( Artifact :: from ( f. try_into_std ( ) . unwrap ( ) ) ) )
211
+ Ok ( Some ( Artifact :: new ( Box :: new ( f. try_into_std ( ) . unwrap ( ) ) ) ? ) )
210
212
}
211
213
}
212
214
} else {
You can’t perform that action at this time.
0 commit comments