@@ -94,7 +94,7 @@ impl<'gctx> PathSource<'gctx> {
9494 /// use other methods like `.gitignore`, `package.include`, or
9595 /// `package.exclude` to filter the list of files.
9696 #[ 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 > > {
9898 list_files ( pkg, self . gctx )
9999 }
100100
@@ -278,7 +278,7 @@ impl<'gctx> RecursivePathSource<'gctx> {
278278 /// are relevant for building this package, but it also contains logic to
279279 /// use other methods like `.gitignore`, `package.include`, or
280280 /// `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 > > {
282282 list_files ( pkg, self . gctx )
283283 }
284284
@@ -404,6 +404,32 @@ impl<'gctx> Source for RecursivePathSource<'gctx> {
404404 }
405405}
406406
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+
407433fn first_package < ' p > (
408434 pkg_id : PackageId ,
409435 pkgs : & ' p Vec < Package > ,
@@ -446,7 +472,7 @@ fn first_package<'p>(
446472/// are relevant for building this package, but it also contains logic to
447473/// use other methods like `.gitignore`, `package.include`, or
448474/// `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 > > {
450476 _list_files ( pkg, gctx) . with_context ( || {
451477 format ! (
452478 "failed to determine list of files in {}" ,
@@ -456,7 +482,7 @@ pub fn list_files(pkg: &Package, gctx: &GlobalContext) -> CargoResult<Vec<PathBu
456482}
457483
458484/// 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 > > {
460486 let root = pkg. root ( ) ;
461487 let no_include_option = pkg. manifest ( ) . include ( ) . is_empty ( ) ;
462488 let git_repo = if no_include_option {
@@ -580,7 +606,7 @@ fn list_files_gix(
580606 repo : & gix:: Repository ,
581607 filter : & dyn Fn ( & Path , bool ) -> bool ,
582608 gctx : & GlobalContext ,
583- ) -> CargoResult < Vec < PathBuf > > {
609+ ) -> CargoResult < Vec < PathEntry > > {
584610 debug ! ( "list_files_gix {}" , pkg. package_id( ) ) ;
585611 let options = repo
586612 . dirwalk_options ( ) ?
@@ -619,7 +645,7 @@ fn list_files_gix(
619645 vec ! [ include, exclude]
620646 } ;
621647
622- let mut files = Vec :: < PathBuf > :: new ( ) ;
648+ let mut files = Vec :: < PathEntry > :: new ( ) ;
623649 let mut subpackages_found = Vec :: new ( ) ;
624650 for item in repo
625651 . dirwalk_iter ( index. clone ( ) , pathspec, Default :: default ( ) , options) ?
@@ -701,7 +727,7 @@ fn list_files_gix(
701727 } else if ( filter) ( & file_path, is_dir) {
702728 assert ! ( !is_dir) ;
703729 trace ! ( " found {}" , file_path. display( ) ) ;
704- files. push ( file_path) ;
730+ files. push ( PathEntry { path : file_path } ) ;
705731 }
706732 }
707733
@@ -715,7 +741,7 @@ fn list_files_gix(
715741/// is not tracked under a Git repository.
716742fn list_files_walk (
717743 path : & Path ,
718- ret : & mut Vec < PathBuf > ,
744+ ret : & mut Vec < PathEntry > ,
719745 is_root : bool ,
720746 filter : & dyn Fn ( & Path , bool ) -> bool ,
721747 gctx : & GlobalContext ,
@@ -756,7 +782,9 @@ fn list_files_walk(
756782 Ok ( entry) => {
757783 let file_type = entry. file_type ( ) ;
758784 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+ } ) ;
760788 }
761789 }
762790 Err ( err) if err. loop_ancestor ( ) . is_some ( ) => {
@@ -770,7 +798,9 @@ fn list_files_walk(
770798 // Otherwise, simply recover from it.
771799 // Don't worry about error skipping here, the callers would
772800 // 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+ } ) ,
774804 None => return Err ( err. into ( ) ) ,
775805 } ,
776806 }
@@ -801,7 +831,7 @@ fn last_modified_file(
801831 let mtime = paths:: mtime ( & file) . unwrap_or_else ( |_| FileTime :: zero ( ) ) ;
802832 if mtime > max {
803833 max = mtime;
804- max_path = file;
834+ max_path = file. into_path_buf ( ) ;
805835 }
806836 }
807837 trace ! ( "last modified file {}: {}" , path. display( ) , max) ;
0 commit comments