@@ -160,33 +160,40 @@ mod artifacts_dir {
160
160
build_postfix : BuildPostfix < T > ,
161
161
) -> Result < WasmPath , CwEnvError > {
162
162
let build_postfix: String = build_postfix. into ( ) ;
163
- let path_str = fs:: read_dir ( self . path ( ) ) ?
164
- . find_map ( |entry| {
165
- let path = entry. ok ( ) ?. path ( ) ;
166
- let file_name = path. file_name ( ) . unwrap_or_default ( ) . to_string_lossy ( ) ;
167
- if !path. is_file ( ) {
168
- return None ;
169
- }
170
-
171
- if ( path. extension ( ) . unwrap_or_default ( ) == "wasm"
172
- // If a postfix is provided
173
- && !build_postfix. is_empty ( )
163
+ let mut wasm_with_postfix = None ;
164
+ let mut default_wasm = None ;
165
+
166
+ for entry in fs:: read_dir ( self . path ( ) ) ? {
167
+ let Ok ( entry) = entry else {
168
+ continue ;
169
+ } ;
170
+ let path = entry. path ( ) ;
171
+ let file_name = path. file_name ( ) . unwrap_or_default ( ) . to_string_lossy ( ) ;
172
+ if !path. is_file ( ) {
173
+ continue ;
174
+ }
175
+ if path. extension ( ) . unwrap_or_default ( ) == "wasm" {
176
+ // If a postfix is provided
177
+ if !build_postfix. is_empty ( )
174
178
// It needs to be in the the file name as well.
175
- && is_artifact_with_build_postfix ( & file_name, name, & build_postfix) )
176
- // If not found, check if the default build is present.
177
- || is_default_artifact ( & file_name, name)
179
+ && is_artifact_with_build_postfix ( & file_name, name, & build_postfix)
178
180
{
179
- Some ( file_name. into_owned ( ) )
180
- } else {
181
- None
181
+ wasm_with_postfix = Some ( file_name. into_owned ( ) ) ;
182
+ break ;
183
+ }
184
+ // If not found, check if the default build is present.
185
+ else if is_default_artifact ( & file_name, name) {
186
+ default_wasm = Some ( file_name. into_owned ( ) )
182
187
}
183
- } )
184
- . ok_or_else ( || {
185
- CwEnvError :: WasmNotFound (
186
- name. to_owned ( ) ,
187
- self . path ( ) . to_str ( ) . unwrap_or_default ( ) . to_owned ( ) ,
188
- )
189
- } ) ?;
188
+ }
189
+ }
190
+
191
+ let path_str = wasm_with_postfix. or ( default_wasm) . ok_or_else ( || {
192
+ CwEnvError :: WasmNotFound (
193
+ name. to_owned ( ) ,
194
+ self . path ( ) . to_str ( ) . unwrap_or_default ( ) . to_owned ( ) ,
195
+ )
196
+ } ) ?;
190
197
WasmPath :: new ( self . path ( ) . join ( path_str) )
191
198
}
192
199
}
0 commit comments