253
255
load_file(Mod, Caller, St)
256
handle_call({add_path,Where,Dir0}, {_From,_Tag}, S=#state{cache=Cache0}) ->
258
handle_call({add_path,Where,Dir0}, {_From,_Tag},
259
#state{cache=Cache0,namedb=Namedb,path=Path0}=S) ->
259
{Resp,Path} = add_path(Where, Dir0, S#state.path, S#state.namedb),
262
{Resp,Path} = add_path(Where, Dir0, Path0, Namedb),
260
263
{reply,Resp,S#state{path=Path}};
262
265
Dir = absname(Dir0), %% Cache always expands the path
263
{Resp,Path} = add_path(Where, Dir, S#state.path, S#state.namedb),
264
Cache=update_cache([Dir],Where,Cache0),
266
{Resp,Path} = add_path(Where, Dir, Path0, Namedb),
267
Cache = update_cache([Dir], Where, Cache0),
265
268
{reply,Resp,S#state{path=Path,cache=Cache}}
268
handle_call({add_paths,Where,Dirs0}, {_From,_Tag}, S=#state{cache=Cache0}) ->
271
handle_call({add_paths,Where,Dirs0}, {_From,_Tag},
272
#state{cache=Cache0,namedb=Namedb,path=Path0}=S) ->
271
{Resp,Path} = add_paths(Where,Dirs0,S#state.path,S#state.namedb),
272
{reply,Resp, S#state{path=Path}};
275
{Resp,Path} = add_paths(Where, Dirs0, Path0, Namedb),
276
{reply,Resp,S#state{path=Path}};
274
278
%% Cache always expands the path
275
279
Dirs = [absname(Dir) || Dir <- Dirs0],
276
{Resp,Path} = add_paths(Where, Dirs, S#state.path, S#state.namedb),
280
{Resp,Path} = add_paths(Where, Dirs, Path0, Namedb),
277
281
Cache=update_cache(Dirs,Where,Cache0),
278
282
{reply,Resp,S#state{cache=Cache,path=Path}}
281
handle_call({set_path,PathList}, {_From,_Tag}, S) ->
283
{Resp, NewPath,NewDb} = set_path(PathList, Path, S#state.namedb),
284
{reply,Resp,rehash_cache(S#state{path = NewPath, namedb=NewDb})};
286
handle_call({del_path,Name}, {_From,_Tag}, S) ->
287
{Resp,Path} = del_path(Name,S#state.path,S#state.namedb),
288
{reply,Resp,rehash_cache(S#state{path = Path})};
290
handle_call({replace_path,Name,Dir}, {_From,_Tag}, S) ->
291
{Resp,Path} = replace_path(Name,Dir,S#state.path,S#state.namedb),
292
{reply,Resp,rehash_cache(S#state{path = Path})};
285
handle_call({set_path,PathList}, {_From,_Tag},
286
#state{path=Path0,namedb=Namedb}=S) ->
287
{Resp,Path,NewDb} = set_path(PathList, Path0, Namedb),
288
{reply,Resp,rehash_cache(S#state{path=Path,namedb=NewDb})};
290
handle_call({del_path,Name}, {_From,_Tag},
291
#state{path=Path0,namedb=Namedb}=S) ->
292
{Resp,Path} = del_path(Name, Path0, Namedb),
293
{reply,Resp,rehash_cache(S#state{path=Path})};
295
handle_call({replace_path,Name,Dir}, {_From,_Tag},
296
#state{path=Path0,namedb=Namedb}=S) ->
297
{Resp,Path} = replace_path(Name, Dir, Path0, Namedb),
298
{reply,Resp,rehash_cache(S#state{path=Path})};
294
300
handle_call(rehash, {_From,_Tag}, S0) ->
295
301
S = create_cache(S0),
311
317
do_load_binary(Mod, File, Bin, Caller, S);
313
319
handle_call({load_native_partial,Mod,Bin}, {_From,_Tag}, S) ->
314
Result = (catch hipe_unified_loader:load(Mod,Bin)),
320
Result = (catch hipe_unified_loader:load(Mod, Bin)),
315
321
Status = hipe_result_to_status(Result),
316
322
{reply,Status,S};
318
324
handle_call({load_native_sticky,Mod,Bin,WholeModule}, {_From,_Tag}, S) ->
319
Result = (catch hipe_unified_loader:load_module(Mod,Bin,WholeModule)),
325
Result = (catch hipe_unified_loader:load_module(Mod, Bin, WholeModule)),
320
326
Status = hipe_result_to_status(Result),
321
327
{reply,Status,S};
384
390
handle_call({is_cached,_File}, {_From,_Tag}, S=#state{cache=no_cache}) ->
387
handle_call({set_primary_archive, File, ArchiveBin}, {_From,_Tag}, S=#state{mode=Mode}) ->
388
case erl_prim_loader:set_primary_archive(File, ArchiveBin) of
393
handle_call({set_primary_archive, File, ArchiveBin, FileInfo}, {_From,_Tag}, S=#state{mode=Mode}) ->
394
case erl_prim_loader:set_primary_archive(File, ArchiveBin, FileInfo) of
390
396
{reply, {ok, Mode, Files}, S};
392
{reply, {error, Reason}, S}
397
{error, _Reason} = Error ->
395
401
handle_call({is_cached,File}, {_From,_Tag}, S=#state{cache=Cache}) ->
499
504
%% Create the initial path.
501
make_path(BundleDir,Bundles0) ->
506
make_path(BundleDir, Bundles0) ->
502
507
Bundles = choose_bundles(Bundles0),
503
make_path(BundleDir,Bundles,[],[]).
508
make_path(BundleDir, Bundles, [], []).
505
510
choose_bundles(Bundles) ->
506
511
ArchiveExt = archive_extension(),
507
Bs = lists:sort([create_bundle(B,ArchiveExt) || B <- Bundles]),
512
Bs = lists:sort([create_bundle(B, ArchiveExt) || B <- Bundles]),
508
513
[FullName || {_Name,_NumVsn,FullName} <-
509
514
choose(lists:reverse(Bs), [], ArchiveExt)].
511
create_bundle(FullName,ArchiveExt) ->
512
BaseName = filename:basename(FullName,ArchiveExt),
516
create_bundle(FullName, ArchiveExt) ->
517
BaseName = filename:basename(FullName, ArchiveExt),
513
518
case split(BaseName, "-") of
514
Toks when length(Toks) > 1 ->
515
520
VsnStr = lists:last(Toks),
516
521
case vsn_to_num(VsnStr) of
518
Name = join(lists:sublist(Toks,length(Toks)-1),"-"),
523
Name = join(lists:sublist(Toks, length(Toks)-1),"-"),
519
524
{Name,VsnNum,FullName};
521
{FullName, [0], FullName}
526
{FullName,[0],FullName}
524
529
{FullName,[0],FullName}
835
840
%% then the table is created :-)
837
842
do_add(first,Dir,Path,NameDb) ->
839
844
[Dir|lists:delete(Dir,Path)];
840
845
do_add(last,Dir,Path,NameDb) ->
841
846
case lists:member(Dir,Path) of
845
maybe_update(Dir,NameDb),
850
maybe_update(Dir, NameDb),
849
854
%% Do not update if the same name already exists !
850
maybe_update(Dir,NameDb) ->
851
case lookup_name(get_name(Dir),NameDb) of
852
false -> update(Dir,NameDb);
855
maybe_update(Dir, NameDb) ->
856
(lookup_name(get_name(Dir), NameDb) =:= false) andalso update(Dir, NameDb).
856
858
update(_Dir, false) ->
858
update(Dir,NameDb) ->
859
replace_name(Dir,NameDb).
860
update(Dir, NameDb) ->
861
replace_name(Dir, NameDb).
864
864
%% Set a completely new path.