@@ -162,8 +162,11 @@ pub fn query_cache_path(sess: &Session) -> PathBuf {
162
162
fn lock_file_path ( session_dir : & Path ) -> PathBuf {
163
163
let crate_dir = session_dir. parent ( ) . unwrap ( ) ;
164
164
165
- let directory_name = session_dir. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
166
- assert_no_characters_lost ( & directory_name) ;
165
+ let directory_name = session_dir
166
+ . file_name ( )
167
+ . unwrap ( )
168
+ . to_str ( )
169
+ . expect ( "malformed session dir name: contains non-Unicode characters" ) ;
167
170
168
171
let dash_indices: Vec < _ > = directory_name. match_indices ( '-' ) . map ( |( idx, _) | idx) . collect ( ) ;
169
172
if dash_indices. len ( ) != 3 {
@@ -329,8 +332,11 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
329
332
330
333
debug ! ( "finalize_session_directory() - session directory: {}" , incr_comp_session_dir. display( ) ) ;
331
334
332
- let old_sub_dir_name = incr_comp_session_dir. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
333
- assert_no_characters_lost ( & old_sub_dir_name) ;
335
+ let old_sub_dir_name = incr_comp_session_dir
336
+ . file_name ( )
337
+ . unwrap ( )
338
+ . to_str ( )
339
+ . expect ( "malformed session dir name: contains non-Unicode characters" ) ;
334
340
335
341
// Keep the 's-{timestamp}-{random-number}' prefix, but replace the
336
342
// '-working' part with the SVH of the crate
@@ -527,8 +533,10 @@ where
527
533
for session_dir in iter {
528
534
debug ! ( "find_source_directory_in_iter - inspecting `{}`" , session_dir. display( ) ) ;
529
535
530
- let directory_name = session_dir. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
531
- assert_no_characters_lost ( & directory_name) ;
536
+ let Some ( directory_name) = session_dir. file_name ( ) . unwrap ( ) . to_str ( ) else {
537
+ debug ! ( "find_source_directory_in_iter - ignoring" ) ;
538
+ continue ;
539
+ } ;
532
540
533
541
if source_directories_already_tried. contains ( & session_dir)
534
542
|| !is_session_directory ( & directory_name)
@@ -619,12 +627,6 @@ fn crate_path(sess: &Session) -> PathBuf {
619
627
incr_dir. join ( crate_name)
620
628
}
621
629
622
- fn assert_no_characters_lost ( s : & str ) {
623
- if s. contains ( '\u{FFFD}' ) {
624
- bug ! ( "Could not losslessly convert '{}'." , s)
625
- }
626
- }
627
-
628
630
fn is_old_enough_to_be_collected ( timestamp : SystemTime ) -> bool {
629
631
timestamp < SystemTime :: now ( ) - Duration :: from_secs ( 10 )
630
632
}
@@ -657,14 +659,14 @@ pub(crate) fn garbage_collect_session_directories(sess: &Session) -> io::Result<
657
659
} ;
658
660
659
661
let entry_name = dir_entry. file_name ( ) ;
660
- let entry_name = entry_name. to_string_lossy ( ) ;
662
+ let Some ( entry_name) = entry_name. to_str ( ) else {
663
+ continue ;
664
+ } ;
661
665
662
666
if is_session_directory_lock_file ( & entry_name) {
663
- assert_no_characters_lost ( & entry_name) ;
664
- lock_files. insert ( entry_name. into_owned ( ) ) ;
667
+ lock_files. insert ( entry_name. to_string ( ) ) ;
665
668
} else if is_session_directory ( & entry_name) {
666
- assert_no_characters_lost ( & entry_name) ;
667
- session_directories. insert ( entry_name. into_owned ( ) ) ;
669
+ session_directories. insert ( entry_name. to_string ( ) ) ;
668
670
} else {
669
671
// This is something we don't know, leave it alone
670
672
}
0 commit comments