@@ -9,7 +9,7 @@ use crate::manifest::validate_manifest;
9
9
pub use crate :: vcs_info:: CargoVcsInfo ;
10
10
pub use cargo_manifest:: { Manifest , StringOrBool } ;
11
11
use flate2:: read:: GzDecoder ;
12
- use std:: collections:: { BTreeMap , HashSet } ;
12
+ use std:: collections:: BTreeMap ;
13
13
use std:: io:: Read ;
14
14
use std:: path:: { Path , PathBuf } ;
15
15
use std:: str:: FromStr ;
@@ -33,8 +33,6 @@ pub enum TarballError {
33
33
Malformed ( #[ source] std:: io:: Error ) ,
34
34
#[ error( "invalid path found: {0}" ) ]
35
35
InvalidPath ( String ) ,
36
- #[ error( "duplicate path found: {0}" ) ]
37
- DuplicatePath ( String ) ,
38
36
#[ error( "unexpected symlink or hard link found: {0}" ) ]
39
37
UnexpectedSymlink ( String ) ,
40
38
#[ error( "Cargo.toml manifest is missing" ) ]
@@ -43,6 +41,8 @@ pub enum TarballError {
43
41
InvalidManifest ( #[ from] cargo_manifest:: Error ) ,
44
42
#[ error( "Cargo.toml manifest is incorrectly cased: {0:?}" ) ]
45
43
IncorrectlyCasedManifest ( PathBuf ) ,
44
+ #[ error( "more than one Cargo.toml manifest in tarball: {0:?}" ) ]
45
+ TooManyManifests ( Vec < PathBuf > ) ,
46
46
#[ error( transparent) ]
47
47
IO ( #[ from] std:: io:: Error ) ,
48
48
}
@@ -67,7 +67,6 @@ pub fn process_tarball<R: Read>(
67
67
68
68
let mut vcs_info = None ;
69
69
let mut manifests = BTreeMap :: new ( ) ;
70
- let mut paths = HashSet :: new ( ) ;
71
70
72
71
for entry in archive. entries ( ) ? {
73
72
let mut entry = entry. map_err ( TarballError :: Malformed ) ?;
@@ -94,13 +93,6 @@ pub fn process_tarball<R: Read>(
94
93
) ) ;
95
94
}
96
95
97
- let lowercase_path = entry_path. as_os_str ( ) . to_ascii_lowercase ( ) ;
98
- if !paths. insert ( lowercase_path) {
99
- return Err ( TarballError :: DuplicatePath (
100
- entry_path. display ( ) . to_string ( ) ,
101
- ) ) ;
102
- }
103
-
104
96
// Let's go hunting for the VCS info and crate manifest. The only valid place for these is
105
97
// in the package root in the tarball.
106
98
if entry_path. parent ( ) == Some ( pkg_root) {
@@ -124,6 +116,13 @@ pub fn process_tarball<R: Read>(
124
116
}
125
117
}
126
118
119
+ if manifests. len ( ) > 1 {
120
+ // There are no scenarios where we want to accept a crate file with multiple manifests.
121
+ return Err ( TarballError :: TooManyManifests (
122
+ manifests. into_keys ( ) . collect ( ) ,
123
+ ) ) ;
124
+ }
125
+
127
126
// Although we're interested in all possible cases of `Cargo.toml` above to protect users
128
127
// on case-insensitive filesystems, to match the behaviour of cargo we should only actually
129
128
// accept `Cargo.toml` and (the now deprecated) `cargo.toml` as valid options for the
@@ -302,36 +301,12 @@ mod tests {
302
301
} ;
303
302
304
303
let err = assert_err ! ( process( vec![ "cargo.toml" , "Cargo.toml" ] ) ) ;
305
- assert_snapshot ! ( err, @"duplicate path found: foo-0.0.1/Cargo.toml") ;
304
+ assert_snapshot ! ( err, @r###"more than one Cargo.toml manifest in tarball: [" foo-0.0.1/Cargo.toml", "foo-0.0.1/cargo.toml"]"### ) ;
306
305
307
306
let err = assert_err ! ( process( vec![ "Cargo.toml" , "Cargo.Toml" ] ) ) ;
308
- assert_snapshot ! ( err, @"duplicate path found: foo-0.0.1/Cargo.Toml") ;
307
+ assert_snapshot ! ( err, @r###"more than one Cargo.toml manifest in tarball: [" foo-0.0.1/Cargo.Toml", "foo-0.0.1/Cargo.toml"]"### ) ;
309
308
310
309
let err = assert_err ! ( process( vec![ "Cargo.toml" , "cargo.toml" , "CARGO.TOML" ] ) ) ;
311
- assert_snapshot ! ( err, @"duplicate path found: foo-0.0.1/cargo.toml" ) ;
312
- }
313
-
314
- #[ test]
315
- fn test_duplicate_paths ( ) {
316
- let tarball = TarballBuilder :: new ( )
317
- . add_file ( "foo-0.0.1/Cargo.toml" , MANIFEST )
318
- . add_file ( "foo-0.0.1/foo.rs" , b"" )
319
- . add_file ( "foo-0.0.1/foo.rs" , b"" )
320
- . build ( ) ;
321
-
322
- let err = assert_err ! ( process_tarball( "foo-0.0.1" , & * tarball, MAX_SIZE ) ) ;
323
- assert_snapshot ! ( err, @"duplicate path found: foo-0.0.1/foo.rs" )
324
- }
325
-
326
- #[ test]
327
- fn test_case_insensitivity ( ) {
328
- let tarball = TarballBuilder :: new ( )
329
- . add_file ( "foo-0.0.1/Cargo.toml" , MANIFEST )
330
- . add_file ( "foo-0.0.1/foo.rs" , b"" )
331
- . add_file ( "foo-0.0.1/FOO.rs" , b"" )
332
- . build ( ) ;
333
-
334
- let err = assert_err ! ( process_tarball( "foo-0.0.1" , & * tarball, MAX_SIZE ) ) ;
335
- assert_snapshot ! ( err, @"duplicate path found: foo-0.0.1/FOO.rs" )
310
+ assert_snapshot ! ( err, @r###"more than one Cargo.toml manifest in tarball: ["foo-0.0.1/CARGO.TOML", "foo-0.0.1/Cargo.toml", "foo-0.0.1/cargo.toml"]"### ) ;
336
311
}
337
312
}
0 commit comments