diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel/src/code.erl | 24 | ||||
-rw-r--r-- | lib/kernel/src/code_server.erl | 14 | ||||
-rw-r--r-- | lib/kernel/test/erl_prim_loader_SUITE.erl | 74 | ||||
-rw-r--r-- | lib/stdlib/src/escript.erl | 13 |
4 files changed, 87 insertions, 38 deletions
diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl index fef11d7e6e..89d893f8c1 100644 --- a/lib/kernel/src/code.erl +++ b/lib/kernel/src/code.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(code). @@ -63,7 +63,7 @@ which/1, where_is_file/1, where_is_file/2, - set_primary_archive/2, + set_primary_archive/3, clash/0]). -include_lib("kernel/include/file.hrl"). @@ -101,7 +101,7 @@ %% unstick_dir(Dir) -> ok | error %% is_sticky(Module) -> true | false %% which(Module) -> Filename -%% set_primary_archive((FileName, Bin) -> ok | {error, Reason} +%% set_primary_archive((FileName, Bin, FileInfo) -> ok | {error, Reason} %% clash() -> -> print out %%---------------------------------------------------------------------------- @@ -420,11 +420,15 @@ where_is_file(Path, File) when is_list(Path), is_list(File) -> which(File, ".", Path) end. --spec set_primary_archive(ArchiveFile :: file:filename(), ArchiveBin :: binary()) -> 'ok' | {'error', atom()}. +-spec set_primary_archive(ArchiveFile :: file:filename(), + ArchiveBin :: binary(), + FileInfo :: #file_info{}) + -> 'ok' | {'error', atom()}. -set_primary_archive(ArchiveFile0, ArchiveBin) when is_list(ArchiveFile0), is_binary(ArchiveBin) -> +set_primary_archive(ArchiveFile0, ArchiveBin, FileInfo) + when is_list(ArchiveFile0), is_binary(ArchiveBin), is_record(FileInfo, file_info) -> ArchiveFile = filename:absname(ArchiveFile0), - case call({set_primary_archive, ArchiveFile, ArchiveBin}) of + case call({set_primary_archive, ArchiveFile, ArchiveBin, FileInfo}) of {ok, []} -> ok; {ok, _Mode, Ebins} -> diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl index d4e3f0bcf8..7aeddb73d1 100644 --- a/lib/kernel/src/code_server.erl +++ b/lib/kernel/src/code_server.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1998-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(code_server). @@ -384,8 +384,8 @@ handle_call(stop,{_From,_Tag}, S) -> handle_call({is_cached,_File}, {_From,_Tag}, S=#state{cache=no_cache}) -> {reply, no, S}; -handle_call({set_primary_archive, File, ArchiveBin}, {_From,_Tag}, S=#state{mode=Mode}) -> - case erl_prim_loader:set_primary_archive(File, ArchiveBin) of +handle_call({set_primary_archive, File, ArchiveBin, FileInfo}, {_From,_Tag}, S=#state{mode=Mode}) -> + case erl_prim_loader:set_primary_archive(File, ArchiveBin, FileInfo) of {ok, Files} -> {reply, {ok, Mode, Files}, S}; {error, Reason} -> diff --git a/lib/kernel/test/erl_prim_loader_SUITE.erl b/lib/kernel/test/erl_prim_loader_SUITE.erl index 4d090f4db5..19c84ab34c 100644 --- a/lib/kernel/test/erl_prim_loader_SUITE.erl +++ b/lib/kernel/test/erl_prim_loader_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% -module(erl_prim_loader_SUITE). @@ -27,7 +27,7 @@ inet_existing/1, inet_coming_up/1, inet_disconnects/1, multiple_slaves/1, file_requests/1, local_archive/1, remote_archive/1, - primary_archive/1]). + primary_archive/1, virtual_dir_in_archive/1]). -export([init_per_testcase/2, fin_per_testcase/2]). @@ -41,10 +41,11 @@ all(suite) -> inet_existing, inet_coming_up, inet_disconnects, multiple_slaves, file_requests, local_archive, - remote_archive, primary_archive + remote_archive, primary_archive, + virtual_dir_in_archive ]. -init_per_testcase(Func, Config) when atom(Func), list(Config) -> +init_per_testcase(Func, Config) when is_atom(Func), is_list(Config) -> Dog=?t:timetrap(?t:minutes(3)), [{watchdog, Dog}|Config]. @@ -81,7 +82,7 @@ set_path(Config) when is_list(Config) -> get_file(doc) -> []; get_file(Config) when is_list(Config) -> ?line case erl_prim_loader:get_file("lists" ++ code:objfile_extension()) of - {ok,Bin,File} when binary(Bin), list(File) -> + {ok,Bin,File} when is_binary(Bin), is_list(File) -> ok; _ -> test_server:fail(get_valid_file) @@ -344,8 +345,9 @@ local_archive(Config) when is_list(Config) -> Node = node(), BeamName = "inet.beam", ?line ok = test_archive(Node, Archive, KernelDir, BeamName), - ?line ok = rpc:call(Node, erl_prim_loader, release_archives, []), + %% Cleanup + ?line ok = rpc:call(Node, erl_prim_loader, release_archives, []), ?line ok = file:delete(Archive), ok. @@ -365,6 +367,7 @@ remote_archive(Config) when is_list(Config) -> BeamName = "inet.beam", ?line ok = test_archive(Node, Archive, KernelDir, BeamName), + %% Cleanup ?line stop_node(Node), ?line unlink(BootPid), ?line exit(BootPid, kill), @@ -401,21 +404,22 @@ primary_archive(Config) when is_list(Config) -> ?line Args = " -setcookie " ++ Cookie, ?line {ok,Node} = start_node(primary_archive, Args), ?line wait_really_started(Node, 25), + ?line {_,_,_} = rpc:call(Node, erlang, date, []), %% Set primary archive - ?line {_,_,_} = rpc:call(Node, erlang, date, []), - ?line {ok, Ebins} = rpc:call(Node, erl_prim_loader, set_primary_archive, [Archive, ArchiveBin]), ExpectedEbins = [Archive, DictDir ++ "/ebin", DummyDir ++ "/ebin"], io:format("ExpectedEbins: ~p\n", [ExpectedEbins]), - ?line ExpectedEbins = lists:sort(Ebins), + ?line {ok, FileInfo} = prim_file:read_file_info(Archive), + ?line {ok, Ebins} = rpc:call(Node, erl_prim_loader, set_primary_archive, [Archive, ArchiveBin, FileInfo]), + ?line ExpectedEbins = lists:sort(Ebins), % assert ?line {ok, TopFiles2} = rpc:call(Node, erl_prim_loader, list_dir, [Archive]), ?line [DictDir, DummyDir] = lists:sort(TopFiles2), BeamName = "primary_archive_dict_app.beam", ?line ok = test_archive(Node, Archive, DictDir, BeamName), - ?line {ok, []} = rpc:call(Node, erl_prim_loader, set_primary_archive, [undefined, undefined]), - + %% Cleanup + ?line {ok, []} = rpc:call(Node, erl_prim_loader, set_primary_archive, [undefined, undefined, undefined]), ?line stop_node(Node), ?line ok = file:delete(Archive), ok. @@ -461,6 +465,46 @@ create_archive(Archive, AppDirs) -> io:format("zip:create(~p,\n\t~p,\n\t~p).\n", [Archive, AppDirs, Opts]), zip:create(Archive, AppDirs, Opts). + +virtual_dir_in_archive(suite) -> + []; +virtual_dir_in_archive(doc) -> + ["Read virtual directories from archive."]; +virtual_dir_in_archive(Config) when is_list(Config) -> + PrivDir = ?config(priv_dir, Config), + Data = <<"A little piece of data.">>, + ArchiveBase = "archive_with_virtual_dirs", + Archive = filename:join([PrivDir, ArchiveBase ++ init:archive_extension()]), + FileBase = "a_data_file.beam", + EbinBase = "ebin", + FileInArchive = filename:join([ArchiveBase, EbinBase, FileBase]), + BinFiles = [{FileInArchive, Data}], + Opts = [{compress, []}], + ?line file:delete(Archive), + io:format("zip:create(~p,\n\t~p,\n\t~p).\n", [Archive, BinFiles, Opts]), + ?line {ok, Archive} = zip:create(Archive, BinFiles, Opts), + + %% Verify that there is no directories + ?line {ok, BinFiles} = zip:unzip(Archive, [memory]), + + FullPath = filename:join([Archive, FileInArchive]), + ?line {ok, _} = erl_prim_loader:read_file_info(FullPath), + + %% Read one virtual dir + EbinDir = filename:dirname(FullPath), + ?line {ok, _} = erl_prim_loader:read_file_info(EbinDir), + ?line {ok, [FileBase]} = erl_prim_loader:list_dir(EbinDir), + + %% Read another virtual dir + AppDir = filename:dirname(EbinDir), + ?line {ok, _} = erl_prim_loader:read_file_info(AppDir), + ?line {ok, [EbinBase]} = erl_prim_loader:list_dir(AppDir), + + %% Cleanup + ?line ok = erl_prim_loader:release_archives(), + ?line ok = file:delete(Archive), + ok. + %% Misc. functions ip_str({A, B, C, D}) -> diff --git a/lib/stdlib/src/escript.erl b/lib/stdlib/src/escript.erl index 697a69b801..c0f71fb3f5 100644 --- a/lib/stdlib/src/escript.erl +++ b/lib/stdlib/src/escript.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 2007-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 2007-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% -module(escript). @@ -180,7 +180,8 @@ parse_and_run(File, Args, Options) -> is_binary(FormsOrBin) -> case Source of archive -> - case code:set_primary_archive(File, FormsOrBin) of + {ok, FileInfo} = file:read_file_info(File), + case code:set_primary_archive(File, FormsOrBin, FileInfo) of ok when CheckOnly -> case code:load_file(Module) of {module, _} -> |