1
1
use std:: collections:: { HashMap , HashSet } ;
2
2
use std:: fs:: File ;
3
- use std:: io:: { prelude:: * , SeekFrom } ;
3
+ use std:: io:: { self , prelude:: * , SeekFrom } ;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
6
6
use crate :: support:: find_json_mismatch;
7
7
use crate :: support:: registry:: { self , alt_api_path} ;
8
8
9
- use byteorder:: { LittleEndian , ReadBytesExt } ;
10
9
use flate2:: read:: GzDecoder ;
11
10
use tar:: Archive ;
12
11
12
+ fn read_le_u32 < R > ( mut reader : R ) -> io:: Result < u32 >
13
+ where
14
+ R : Read ,
15
+ {
16
+ let mut buf = [ 0 ; 4 ] ;
17
+ reader. read_exact ( & mut buf) ?;
18
+ Ok ( u32:: from_le_bytes ( buf) )
19
+ }
20
+
13
21
/// Checks the result of a crate publish.
14
22
pub fn validate_upload ( expected_json : & str , expected_crate_name : & str , expected_files : & [ & str ] ) {
15
23
let new_path = registry:: api_path ( ) . join ( "api/v1/crates/new" ) ;
@@ -44,7 +52,7 @@ fn _validate_upload(
44
52
) {
45
53
let mut f = File :: open ( new_path) . unwrap ( ) ;
46
54
// 32-bit little-endian integer of length of JSON data.
47
- let json_sz = f . read_u32 :: < LittleEndian > ( ) . expect ( "read json length" ) ;
55
+ let json_sz = read_le_u32 ( & mut f ) . expect ( "read json length" ) ;
48
56
let mut json_bytes = vec ! [ 0 ; json_sz as usize ] ;
49
57
f. read_exact ( & mut json_bytes) . expect ( "read JSON data" ) ;
50
58
let actual_json = serde_json:: from_slice ( & json_bytes) . expect ( "uploaded JSON should be valid" ) ;
@@ -53,7 +61,7 @@ fn _validate_upload(
53
61
. expect ( "uploaded JSON did not match expected JSON" ) ;
54
62
55
63
// 32-bit little-endian integer of length of crate file.
56
- let crate_sz = f . read_u32 :: < LittleEndian > ( ) . expect ( "read crate length" ) ;
64
+ let crate_sz = read_le_u32 ( & mut f ) . expect ( "read crate length" ) ;
57
65
let mut krate_bytes = vec ! [ 0 ; crate_sz as usize ] ;
58
66
f. read_exact ( & mut krate_bytes) . expect ( "read crate data" ) ;
59
67
// Check at end.
0 commit comments