@@ -866,28 +866,57 @@ check(Mod) when is_atom(Mod) -> catch check_module(Mod);
866
866
check (File ) when is_list (File ) -> catch check_file (File ).
867
867
868
868
load ({Mod , Src , Beam , BeamBin , Exp , Abst }, Dist ) ->
869
- _ = everywhere (Dist ,
870
- fun () ->
871
- code :purge (Mod ),
872
- erts_debug :breakpoint ({Mod ,'_' ,'_' }, false ),
873
- {module ,Mod } = code :load_binary (Mod , Beam , BeamBin )
874
- end ),
875
- case erl_prim_loader :read_file (filename :absname (Src )) of
876
- {ok , SrcBin } ->
877
- MD5 = code :module_md5 (BeamBin ),
878
- SrcBin1 = unicode :characters_to_binary (SrcBin , enc (SrcBin )),
879
- true = is_binary (SrcBin1 ),
880
- Bin = term_to_binary ({interpreter_module ,Exp ,Abst ,SrcBin1 ,MD5 }),
881
- {module , Mod } = dbg_iserver :safe_call ({load , Mod , Src , Bin }),
882
- _ = everywhere (Dist ,
883
- fun () ->
884
- true = erts_debug :breakpoint ({Mod ,'_' ,'_' }, true ) > 0
885
- end ),
886
- {module , Mod };
887
- error ->
888
- error
869
+ RawLoadResult = everywhere (Dist ,
870
+ fun () ->
871
+ code :purge (Mod ),
872
+ erts_debug :breakpoint ({Mod , '_' , '_' }, false ),
873
+ code :load_binary (Mod , Beam , BeamBin )
874
+ end ),
875
+ LoadResult = extract_result (RawLoadResult ),
876
+ case LoadResult of
877
+ {module , Mod } ->
878
+ case erl_prim_loader :read_file (filename :absname (Src )) of
879
+ {ok , SrcBin } ->
880
+ MD5 = code :module_md5 (BeamBin ),
881
+ SrcBin1 = unicode :characters_to_binary (SrcBin , enc (SrcBin )),
882
+ true = is_binary (SrcBin1 ),
883
+ Bin = term_to_binary ({interpreter_module , Exp , Abst , SrcBin1 , MD5 }),
884
+ {module , Mod } = dbg_iserver :safe_call ({load , Mod , Src , Bin }),
885
+ _ = everywhere (Dist ,
886
+ fun () ->
887
+ true = erts_debug :breakpoint ({Mod , '_' , '_' }, true ) > 0
888
+ end ),
889
+ {module , Mod };
890
+ error ->
891
+ error
892
+ end ;
893
+ {error , _ } ->
894
+ error ;
895
+ {badrpc , _ } ->
896
+ error
889
897
end .
890
898
899
+ extract_result ({Results , _BadNodes }) when is_list (Results ) ->
900
+ % % In distributed mode, rpc:multicall returns {Results, BadNodes}.
901
+ % % Look for any successful result in the list.
902
+ case lists :filter (fun
903
+ ({module , _ }) -> true ;
904
+ (_ ) -> false
905
+ end , Results ) of
906
+ [] ->
907
+ % % No node succeeded; return the first result from Results,
908
+ % % which should be an error tuple or badrpc tuple.
909
+ case Results of
910
+ [First | _ ] -> First ;
911
+ [] -> error
912
+ end ;
913
+ [Success | _ ] ->
914
+ Success
915
+ end ;
916
+ extract_result (Result ) ->
917
+ % % For local (non-distributed) calls, the result is returned directly.
918
+ Result .
919
+
891
920
check_module (Mod ) ->
892
921
case code :which (Mod ) of
893
922
Beam when is_list (Beam ) ->
0 commit comments