@@ -71,8 +71,25 @@ impl<'a> ProjectBuilder<'a> {
71
71
} )
72
72
} ) ;
73
73
74
- // Process sequentially with &mut self
75
- let collected_entries = Arc :: try_unwrap ( collected) . unwrap ( ) . into_inner ( ) . unwrap ( ) ;
74
+ // Process sequentially with &mut self without panicking on Arc/Mutex unwraps
75
+ let collected_entries = match Arc :: try_unwrap ( collected) {
76
+ // We are the sole owner of the Arc
77
+ Ok ( mutex) => match mutex. into_inner ( ) {
78
+ // Mutex not poisoned
79
+ Ok ( entries) => entries,
80
+ // Recover entries even if the mutex was poisoned
81
+ Err ( poisoned) => poisoned. into_inner ( ) ,
82
+ } ,
83
+ // There are still other Arc references; lock and take the contents
84
+ Err ( arc) => match arc. lock ( ) {
85
+ Ok ( mut guard) => std:: mem:: take ( & mut * guard) ,
86
+ // Recover guard even if poisoned, then take contents
87
+ Err ( poisoned) => {
88
+ let mut guard = poisoned. into_inner ( ) ;
89
+ std:: mem:: take ( & mut * guard)
90
+ }
91
+ } ,
92
+ } ;
76
93
for entry in collected_entries {
77
94
entry_types. push ( self . build_entry_type ( entry) ?) ;
78
95
}
@@ -89,11 +106,10 @@ impl<'a> ProjectBuilder<'a> {
89
106
if is_dir {
90
107
return Ok ( EntryType :: Directory ( absolute_path. to_owned ( ) , relative_path. to_owned ( ) ) ) ;
91
108
}
92
- let file_name = relative_path
93
- . file_name ( )
94
- . expect ( "expected a file_name" )
95
- . to_string_lossy ( )
96
- . to_lowercase ( ) ;
109
+ let file_name = match relative_path. file_name ( ) {
110
+ Some ( name) => name. to_string_lossy ( ) . to_lowercase ( ) ,
111
+ None => return Ok ( EntryType :: NullEntry ( ) ) ,
112
+ } ;
97
113
98
114
match file_name. as_str ( ) {
99
115
name if name == "package.yml"
@@ -142,11 +158,14 @@ impl<'a> ProjectBuilder<'a> {
142
158
}
143
159
EntryType :: Directory ( absolute_path, relative_path) => {
144
160
if relative_path. parent ( ) == Some ( Path :: new ( & self . config . vendored_gems_path ) ) {
145
- let file_name = relative_path. file_name ( ) . expect ( "expected a file_name" ) ;
146
- gems. push ( VendoredGem {
147
- path : absolute_path,
148
- name : file_name. to_string_lossy ( ) . to_string ( ) ,
149
- } ) ;
161
+ if let Some ( file_name) = relative_path. file_name ( ) {
162
+ gems. push ( VendoredGem {
163
+ path : absolute_path,
164
+ name : file_name. to_string_lossy ( ) . to_string ( ) ,
165
+ } ) ;
166
+ } else {
167
+ warn ! ( "Vendored gem path without file name: {:?}" , relative_path) ;
168
+ }
150
169
}
151
170
}
152
171
EntryType :: RubyPackage ( absolute_path, relative_path) => {
0 commit comments