@@ -10,7 +10,6 @@ use anyhow::Context as _;
10
10
use cargo_util:: paths;
11
11
use filetime:: FileTime ;
12
12
use ignore:: gitignore:: GitignoreBuilder ;
13
- use ignore:: Match ;
14
13
use log:: { trace, warn} ;
15
14
use walkdir:: WalkDir ;
16
15
@@ -131,39 +130,36 @@ impl<'cfg> PathSource<'cfg> {
131
130
}
132
131
let ignore_include = include_builder. build ( ) ?;
133
132
134
- let ignore_should_package = |relative_path : & Path , is_dir : bool | -> CargoResult < bool > {
133
+ let ignore_should_package = |relative_path : & Path , is_dir : bool | {
135
134
// "Include" and "exclude" options are mutually exclusive.
136
135
if no_include_option {
137
- match ignore_exclude. matched_path_or_any_parents ( relative_path, is_dir) {
138
- Match :: None => Ok ( true ) ,
139
- Match :: Ignore ( _) => Ok ( false ) ,
140
- Match :: Whitelist ( _) => Ok ( true ) ,
141
- }
136
+ !ignore_exclude
137
+ . matched_path_or_any_parents ( relative_path, is_dir)
138
+ . is_ignore ( )
142
139
} else {
143
140
if is_dir {
144
141
// Generally, include directives don't list every
145
142
// directory (nor should they!). Just skip all directory
146
143
// checks, and only check files.
147
- return Ok ( true ) ;
144
+ return true ;
148
145
}
149
- match ignore_include
146
+ ignore_include
150
147
. matched_path_or_any_parents ( relative_path, /* is_dir */ false )
151
- {
152
- Match :: None => Ok ( false ) ,
153
- Match :: Ignore ( _) => Ok ( true ) ,
154
- Match :: Whitelist ( _) => Ok ( false ) ,
155
- }
148
+ . is_ignore ( )
156
149
}
157
150
} ;
158
151
159
- let mut filter = |path : & Path , is_dir : bool | -> CargoResult < bool > {
160
- let relative_path = path. strip_prefix ( root) ?;
152
+ let mut filter = |path : & Path , is_dir : bool | {
153
+ let relative_path = match path. strip_prefix ( root) {
154
+ Ok ( p) => p,
155
+ Err ( _) => return false ,
156
+ } ;
161
157
162
158
let rel = relative_path. as_os_str ( ) ;
163
159
if rel == "Cargo.lock" {
164
- return Ok ( pkg. include_lockfile ( ) ) ;
160
+ return pkg. include_lockfile ( ) ;
165
161
} else if rel == "Cargo.toml" {
166
- return Ok ( true ) ;
162
+ return true ;
167
163
}
168
164
169
165
ignore_should_package ( relative_path, is_dir)
@@ -225,7 +221,7 @@ impl<'cfg> PathSource<'cfg> {
225
221
& self ,
226
222
pkg : & Package ,
227
223
repo : & git2:: Repository ,
228
- filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
224
+ filter : & mut dyn FnMut ( & Path , bool ) -> bool ,
229
225
) -> CargoResult < Vec < PathBuf > > {
230
226
warn ! ( "list_files_git {}" , pkg. package_id( ) ) ;
231
227
let index = repo. index ( ) ?;
@@ -347,7 +343,7 @@ impl<'cfg> PathSource<'cfg> {
347
343
PathSource :: walk ( & file_path, & mut ret, false , filter) ?;
348
344
}
349
345
}
350
- } else if ( * filter) ( & file_path, is_dir) ? {
346
+ } else if filter ( & file_path, is_dir) {
351
347
assert ! ( !is_dir) ;
352
348
// We found a file!
353
349
warn ! ( " found {}" , file_path. display( ) ) ;
@@ -379,7 +375,7 @@ impl<'cfg> PathSource<'cfg> {
379
375
fn list_files_walk (
380
376
& self ,
381
377
pkg : & Package ,
382
- filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
378
+ filter : & mut dyn FnMut ( & Path , bool ) -> bool ,
383
379
) -> CargoResult < Vec < PathBuf > > {
384
380
let mut ret = Vec :: new ( ) ;
385
381
PathSource :: walk ( pkg. root ( ) , & mut ret, true , filter) ?;
@@ -390,7 +386,7 @@ impl<'cfg> PathSource<'cfg> {
390
386
path : & Path ,
391
387
ret : & mut Vec < PathBuf > ,
392
388
is_root : bool ,
393
- filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
389
+ filter : & mut dyn FnMut ( & Path , bool ) -> bool ,
394
390
) -> CargoResult < ( ) > {
395
391
let walkdir = WalkDir :: new ( path)
396
392
. follow_links ( true )
@@ -400,7 +396,7 @@ impl<'cfg> PathSource<'cfg> {
400
396
let at_root = is_root && entry. depth ( ) == 0 ;
401
397
let is_dir = entry. file_type ( ) . is_dir ( ) ;
402
398
403
- if !at_root && !filter ( path, is_dir) . unwrap ( ) {
399
+ if !at_root && !filter ( path, is_dir) {
404
400
return false ;
405
401
}
406
402
0 commit comments