11mod diagnostics;
22mod extractor;
3+ mod file_paths;
34mod trap;
45
56#[ macro_use]
@@ -122,15 +123,15 @@ fn main() -> std::io::Result<()> {
122123 let src_archive_dir = matches
123124 . value_of ( "source-archive-dir" )
124125 . expect ( "missing --source-archive-dir" ) ;
125- let src_archive_dir = PathBuf :: from ( src_archive_dir) ;
126+ let src_archive_dir = file_paths :: path_from_string ( src_archive_dir) ;
126127
127128 let trap_dir = matches
128129 . value_of ( "output-dir" )
129130 . expect ( "missing --output-dir" ) ;
130- let trap_dir = PathBuf :: from ( trap_dir) ;
131+ let trap_dir = file_paths :: path_from_string ( trap_dir) ;
131132
132133 let file_list = matches. value_of ( "file-list" ) . expect ( "missing --file-list" ) ;
133- let file_list = fs:: File :: open ( file_list) ?;
134+ let file_list = fs:: File :: open ( file_paths :: path_from_string ( file_list) ) ?;
134135
135136 let language = tree_sitter_ruby:: language ( ) ;
136137 let erb = tree_sitter_embedded_template:: language ( ) ;
@@ -148,7 +149,7 @@ fn main() -> std::io::Result<()> {
148149 . try_for_each ( |line| {
149150 let mut diagnostics_writer = diagnostics. logger ( ) ;
150151 let path = PathBuf :: from ( line) . canonicalize ( ) ?;
151- let src_archive_file = path_for ( & src_archive_dir, & path, "" ) ;
152+ let src_archive_file = file_paths :: path_for ( & src_archive_dir, & path, "" ) ;
152153 let mut source = std:: fs:: read ( & path) ?;
153154 let mut needs_conversion = false ;
154155 let code_ranges;
@@ -164,7 +165,7 @@ fn main() -> std::io::Result<()> {
164165 & path,
165166 & source,
166167 & [ ] ,
167- ) ? ;
168+ ) ;
168169
169170 let ( ranges, line_breaks) = scan_erb (
170171 erb,
@@ -205,7 +206,7 @@ fn main() -> std::io::Result<()> {
205206 "character-decoding-error" ,
206207 "Character decoding error" ,
207208 )
208- . file ( & path . to_string_lossy ( ) )
209+ . file ( & file_paths :: normalize_path ( & path ) )
209210 . message (
210211 "Could not decode the file contents as {}: {}. The contents of the file must match the character encoding specified in the {} {}." ,
211212 & [
@@ -225,7 +226,7 @@ fn main() -> std::io::Result<()> {
225226 diagnostics_writer. write (
226227 diagnostics_writer
227228 . new_entry ( "unknown-character-encoding" , "Unknown character encoding" )
228- . file ( & path . to_string_lossy ( ) )
229+ . file ( & file_paths :: normalize_path ( & path ) )
229230 . message (
230231 "Unknown character encoding {} in {} {}." ,
231232 & [
@@ -251,7 +252,7 @@ fn main() -> std::io::Result<()> {
251252 & path,
252253 & source,
253254 & code_ranges,
254- ) ? ;
255+ ) ;
255256 std:: fs:: create_dir_all ( & src_archive_file. parent ( ) . unwrap ( ) ) ?;
256257 if needs_conversion {
257258 std:: fs:: write ( & src_archive_file, & source) ?;
@@ -274,7 +275,7 @@ fn write_trap(
274275 trap_writer : & trap:: Writer ,
275276 trap_compression : trap:: Compression ,
276277) -> std:: io:: Result < ( ) > {
277- let trap_file = path_for ( trap_dir, & path, trap_compression. extension ( ) ) ;
278+ let trap_file = file_paths :: path_for ( trap_dir, & path, trap_compression. extension ( ) ) ;
278279 std:: fs:: create_dir_all ( & trap_file. parent ( ) . unwrap ( ) ) ?;
279280 trap_writer. write_to_file ( & trap_file, trap_compression)
280281}
@@ -321,54 +322,6 @@ fn scan_erb(
321322 ( result, line_breaks)
322323}
323324
324- fn path_for ( dir : & Path , path : & Path , ext : & str ) -> PathBuf {
325- let mut result = PathBuf :: from ( dir) ;
326- for component in path. components ( ) {
327- match component {
328- std:: path:: Component :: Prefix ( prefix) => match prefix. kind ( ) {
329- std:: path:: Prefix :: Disk ( letter) | std:: path:: Prefix :: VerbatimDisk ( letter) => {
330- result. push ( format ! ( "{}_" , letter as char ) )
331- }
332- std:: path:: Prefix :: Verbatim ( x) | std:: path:: Prefix :: DeviceNS ( x) => {
333- result. push ( x) ;
334- }
335- std:: path:: Prefix :: UNC ( server, share)
336- | std:: path:: Prefix :: VerbatimUNC ( server, share) => {
337- result. push ( "unc" ) ;
338- result. push ( server) ;
339- result. push ( share) ;
340- }
341- } ,
342- std:: path:: Component :: RootDir => {
343- // skip
344- }
345- std:: path:: Component :: Normal ( _) => {
346- result. push ( component) ;
347- }
348- std:: path:: Component :: CurDir => {
349- // skip
350- }
351- std:: path:: Component :: ParentDir => {
352- result. pop ( ) ;
353- }
354- }
355- }
356- if !ext. is_empty ( ) {
357- match result. extension ( ) {
358- Some ( x) => {
359- let mut new_ext = x. to_os_string ( ) ;
360- new_ext. push ( "." ) ;
361- new_ext. push ( ext) ;
362- result. set_extension ( new_ext) ;
363- }
364- None => {
365- result. set_extension ( ext) ;
366- }
367- }
368- }
369- result
370- }
371-
372325fn skip_space ( content : & [ u8 ] , index : usize ) -> usize {
373326 let mut index = index;
374327 while index < content. len ( ) {
@@ -382,7 +335,6 @@ fn skip_space(content: &[u8], index: usize) -> usize {
382335 }
383336 index
384337}
385-
386338fn scan_coding_comment ( content : & [ u8 ] ) -> std:: option:: Option < Cow < str > > {
387339 let mut index = 0 ;
388340 // skip UTF-8 BOM marker if there is one
0 commit comments