@@ -92,47 +92,41 @@ pub fn contains_tmcignore(entry: &DirEntry) -> bool {
9292
9393// Copies the entry to the destination. Parses and filters text files according to `filter`
9494fn copy_file (
95- entry : & DirEntry ,
95+ file : & Path ,
9696 source_root : & Path ,
9797 dest_root : & Path ,
9898 line_filter : & mut impl Fn ( & MetaString ) -> bool ,
9999 file_filter : & mut impl Fn ( & [ MetaString ] ) -> bool ,
100100) -> Result < ( ) , TmcError > {
101- let is_dir = entry. metadata ( ) . map ( |e| e. is_dir ( ) ) . unwrap_or_default ( ) ;
102- if is_dir {
101+ if file. is_dir ( ) {
103102 return Ok ( ( ) ) ;
104103 }
105104 // get relative path
106- let relative_path = entry
107- . path ( )
105+ let relative_path = file
108106 . strip_prefix ( source_root)
109107 . unwrap_or_else ( |_| Path :: new ( "" ) ) ;
110108 let dest_path = dest_root. join ( & relative_path) ;
111109 if let Some ( parent) = dest_path. parent ( ) {
112110 file_util:: create_dir_all ( parent) ?;
113111 }
114- let extension = entry . path ( ) . extension ( ) . and_then ( |e| e. to_str ( ) ) ;
112+ let extension = file . extension ( ) . and_then ( |e| e. to_str ( ) ) ;
115113 let is_binary = extension
116114 . map ( |e| NON_TEXT_TYPES . is_match ( e) )
117115 . unwrap_or_default ( ) ;
118116 if is_binary {
119117 // copy binary files
120- debug ! (
121- "copying binary file from {:?} to {:?}" ,
122- entry. path( ) ,
123- dest_path
124- ) ;
125- file_util:: copy ( entry. path ( ) , & dest_path) ?;
118+ debug ! ( "copying binary file from {:?} to {:?}" , file, dest_path) ;
119+ file_util:: copy ( file, & dest_path) ?;
126120 } else {
127121 // filter text files
128- let source_file = file_util:: open_file ( entry . path ( ) ) ?;
122+ let source_file = file_util:: open_file ( file ) ?;
129123
130124 let parser = MetaSyntaxParser :: new ( source_file, extension. unwrap_or_default ( ) ) ;
131125 let parsed: Vec < MetaString > = parser. collect :: < Result < Vec < _ > , _ > > ( ) ?;
132126
133127 // files that don't pass the filter are skipped
134128 if !file_filter ( & parsed) {
135- log:: debug!( "skipping {} due to file filter" , entry . path ( ) . display( ) ) ;
129+ log:: debug!( "skipping {} due to file filter" , file . display( ) ) ;
136130 return Ok ( ( ) ) ;
137131 }
138132
@@ -152,7 +146,7 @@ fn copy_file(
152146 // writes all lines
153147 log:: debug!(
154148 "filtered file {} to {}" ,
155- entry . path ( ) . display( ) ,
149+ file . display( ) ,
156150 dest_path. display( )
157151 ) ;
158152 file_util:: write_to_file ( & mut write_lines. as_slice ( ) , & dest_path) ?;
@@ -162,20 +156,26 @@ fn copy_file(
162156
163157// Processes all files in path, copying files in directories that are not skipped
164158fn process_files (
165- path : & Path ,
159+ source : & Path ,
166160 dest_root : & Path ,
167161 mut line_filter : impl Fn ( & MetaString ) -> bool ,
168162 mut file_filter : impl Fn ( & [ MetaString ] ) -> bool ,
169163) -> Result < ( ) , TmcError > {
170- info ! ( "Project: {:?}" , path ) ;
164+ info ! ( "Project: {:?}" , source ) ;
171165
172- let walker = WalkDir :: new ( path ) . into_iter ( ) ;
166+ let walker = WalkDir :: new ( source ) . into_iter ( ) ;
173167 // silently skips over errors, for example when there's a directory we don't have permissions for
174168 for entry in walker
175169 . filter_entry ( |e| !is_hidden_dir ( e) && !on_skip_list ( e) && !contains_tmcignore ( e) )
176170 . filter_map ( |e| e. ok ( ) )
177171 {
178- copy_file ( & entry, path, dest_root, & mut line_filter, & mut file_filter) ?;
172+ copy_file (
173+ entry. path ( ) ,
174+ source,
175+ dest_root,
176+ & mut line_filter,
177+ & mut file_filter,
178+ ) ?;
179179 }
180180 Ok ( ( ) )
181181}
0 commit comments