@@ -94,7 +94,7 @@ impl<'gctx> PathSource<'gctx> {
94
94
/// use other methods like `.gitignore`, `package.include`, or
95
95
/// `package.exclude` to filter the list of files.
96
96
#[ tracing:: instrument( skip_all) ]
97
- pub fn list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathBuf > > {
97
+ pub fn list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathEntry > > {
98
98
list_files ( pkg, self . gctx )
99
99
}
100
100
@@ -278,7 +278,7 @@ impl<'gctx> RecursivePathSource<'gctx> {
278
278
/// are relevant for building this package, but it also contains logic to
279
279
/// use other methods like `.gitignore`, `package.include`, or
280
280
/// `package.exclude` to filter the list of files.
281
- pub fn list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathBuf > > {
281
+ pub fn list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathEntry > > {
282
282
list_files ( pkg, self . gctx )
283
283
}
284
284
@@ -404,6 +404,32 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
404
404
}
405
405
}
406
406
407
+ /// [`PathBuf`] with extra metadata.
408
+ #[ derive( Clone , Debug ) ]
409
+ pub struct PathEntry {
410
+ path : PathBuf ,
411
+ }
412
+
413
+ impl PathEntry {
414
+ pub fn into_path_buf ( self ) -> PathBuf {
415
+ self . path
416
+ }
417
+ }
418
+
419
+ impl std:: ops:: Deref for PathEntry {
420
+ type Target = Path ;
421
+
422
+ fn deref ( & self ) -> & Self :: Target {
423
+ self . path . as_path ( )
424
+ }
425
+ }
426
+
427
+ impl AsRef < PathBuf > for PathEntry {
428
+ fn as_ref ( & self ) -> & PathBuf {
429
+ & self . path
430
+ }
431
+ }
432
+
407
433
fn first_package < ' p > (
408
434
pkg_id : PackageId ,
409
435
pkgs : & ' p Vec < Package > ,
@@ -446,7 +472,7 @@ fn first_package<'p>(
446
472
/// are relevant for building this package, but it also contains logic to
447
473
/// use other methods like `.gitignore`, `package.include`, or
448
474
/// `package.exclude` to filter the list of files.
449
- pub fn list_files ( pkg : & Package , gctx : & GlobalContext ) -> CargoResult < Vec < PathBuf > > {
475
+ pub fn list_files ( pkg : & Package , gctx : & GlobalContext ) -> CargoResult < Vec < PathEntry > > {
450
476
_list_files ( pkg, gctx) . with_context ( || {
451
477
format ! (
452
478
"failed to determine list of files in {}" ,
@@ -456,7 +482,7 @@ pub fn list_files(pkg: &Package, gctx: &GlobalContext) -> CargoResult<Vec<PathBu
456
482
}
457
483
458
484
/// See [`PathSource::list_files`].
459
- fn _list_files ( pkg : & Package , gctx : & GlobalContext ) -> CargoResult < Vec < PathBuf > > {
485
+ fn _list_files ( pkg : & Package , gctx : & GlobalContext ) -> CargoResult < Vec < PathEntry > > {
460
486
let root = pkg. root ( ) ;
461
487
let no_include_option = pkg. manifest ( ) . include ( ) . is_empty ( ) ;
462
488
let git_repo = if no_include_option {
@@ -580,7 +606,7 @@ fn list_files_gix(
580
606
repo : & gix:: Repository ,
581
607
filter : & dyn Fn ( & Path , bool ) -> bool ,
582
608
gctx : & GlobalContext ,
583
- ) -> CargoResult < Vec < PathBuf > > {
609
+ ) -> CargoResult < Vec < PathEntry > > {
584
610
debug ! ( "list_files_gix {}" , pkg. package_id( ) ) ;
585
611
let options = repo
586
612
. dirwalk_options ( ) ?
@@ -619,7 +645,7 @@ fn list_files_gix(
619
645
vec ! [ include, exclude]
620
646
} ;
621
647
622
- let mut files = Vec :: < PathBuf > :: new ( ) ;
648
+ let mut files = Vec :: < PathEntry > :: new ( ) ;
623
649
let mut subpackages_found = Vec :: new ( ) ;
624
650
for item in repo
625
651
. dirwalk_iter ( index. clone ( ) , pathspec, Default :: default ( ) , options) ?
@@ -701,7 +727,7 @@ fn list_files_gix(
701
727
} else if ( filter) ( & file_path, is_dir) {
702
728
assert ! ( !is_dir) ;
703
729
trace ! ( " found {}" , file_path. display( ) ) ;
704
- files. push ( file_path) ;
730
+ files. push ( PathEntry { path : file_path } ) ;
705
731
}
706
732
}
707
733
@@ -715,7 +741,7 @@ fn list_files_gix(
715
741
/// is not tracked under a Git repository.
716
742
fn list_files_walk (
717
743
path : & Path ,
718
- ret : & mut Vec < PathBuf > ,
744
+ ret : & mut Vec < PathEntry > ,
719
745
is_root : bool ,
720
746
filter : & dyn Fn ( & Path , bool ) -> bool ,
721
747
gctx : & GlobalContext ,
@@ -756,7 +782,9 @@ fn list_files_walk(
756
782
Ok ( entry) => {
757
783
let file_type = entry. file_type ( ) ;
758
784
if file_type. is_file ( ) || file_type. is_symlink ( ) {
759
- ret. push ( entry. into_path ( ) ) ;
785
+ ret. push ( PathEntry {
786
+ path : entry. into_path ( ) ,
787
+ } ) ;
760
788
}
761
789
}
762
790
Err ( err) if err. loop_ancestor ( ) . is_some ( ) => {
@@ -770,7 +798,9 @@ fn list_files_walk(
770
798
// Otherwise, simply recover from it.
771
799
// Don't worry about error skipping here, the callers would
772
800
// still hit the IO error if they do access it thereafter.
773
- Some ( path) => ret. push ( path. to_path_buf ( ) ) ,
801
+ Some ( path) => ret. push ( PathEntry {
802
+ path : path. to_path_buf ( ) ,
803
+ } ) ,
774
804
None => return Err ( err. into ( ) ) ,
775
805
} ,
776
806
}
@@ -801,7 +831,7 @@ fn last_modified_file(
801
831
let mtime = paths:: mtime ( & file) . unwrap_or_else ( |_| FileTime :: zero ( ) ) ;
802
832
if mtime > max {
803
833
max = mtime;
804
- max_path = file;
834
+ max_path = file. into_path_buf ( ) ;
805
835
}
806
836
}
807
837
trace ! ( "last modified file {}: {}" , path. display( ) , max) ;
0 commit comments