Merge remote branch 'ericbmerritt/master' into rv
* ericbmerritt/master: add beam files to gitignore make insecure nature of ec_file:mkdtemp obvious fixes erlware/erlware_commons#16 fix eunit tests so that they actually work and run make mkdtemp a lot more secure (still not fully secure but more). add . files to gitignore Migrate erlware_commons to rebar support Signed-off-by: Jordan Wilberding <diginux@gmail.com>
This commit is contained in:
commit
8d625ceb46
5 changed files with 41 additions and 53 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
*.beam
|
||||
.*
|
||||
_build
|
||||
erl_crash.dump
|
||||
*.pyc
|
||||
|
|
17
Makefile
17
Makefile
|
@ -1,17 +0,0 @@
|
|||
ERLC=`which erlc`
|
||||
BEAMDIR=./ebin
|
||||
ERLCFLAGS=+debug_info -pa $(BEAMDIR)
|
||||
SRCDIR=src
|
||||
|
||||
.PHONY=all clean
|
||||
|
||||
all:
|
||||
@echo "Erlware Commons is maintained with Sinan, its much better to use "
|
||||
@echo "sinan to build than this makefile. This is here just to get "
|
||||
@echo "get you started."
|
||||
$(ERLC) $(ERLCFLAGS) -o $(BEAMDIR) $(SRCDIR)/ec_dictionary.erl;
|
||||
$(ERLC) $(ERLCFLAGS) -o $(BEAMDIR) $(SRCDIR)/*.erl ;
|
||||
|
||||
clean:
|
||||
rm $(BEAMDIR)/*.beam
|
||||
rm -rf erl_crush.dump
|
3
rebar.config
Normal file
3
rebar.config
Normal file
|
@ -0,0 +1,3 @@
|
|||
{erl_opts,
|
||||
[debug_info,
|
||||
warnings_as_errors]}.
|
|
@ -9,7 +9,7 @@
|
|||
-export([
|
||||
copy/2,
|
||||
copy/3,
|
||||
mkdtemp/0,
|
||||
insecure_mkdtemp/0,
|
||||
mkdir_path/1,
|
||||
find/2,
|
||||
is_symlink/1,
|
||||
|
@ -107,16 +107,23 @@ is_symlink(Path) ->
|
|||
|
||||
%% @doc make a unique temorory directory. Similar function to BSD stdlib
|
||||
%% function of the same name.
|
||||
-spec mkdtemp() -> TmpDirPath::path().
|
||||
mkdtemp() ->
|
||||
UniqueNumber = integer_to_list(element(3, now())),
|
||||
-spec insecure_mkdtemp() -> TmpDirPath::path().
|
||||
insecure_mkdtemp() ->
|
||||
random:seed(now()),
|
||||
UniqueNumber = erlang:integer_to_list(erlang:trunc(random:uniform() * 1000000000000)),
|
||||
TmpDirPath =
|
||||
filename:join([tmp(), lists:flatten([".tmp_dir", UniqueNumber])]),
|
||||
try
|
||||
ok = mkdir_path(TmpDirPath),
|
||||
TmpDirPath
|
||||
catch
|
||||
_C:E -> throw(?UEX({mkdtemp_failed, E}, ?CHECK_PERMS_MSG, []))
|
||||
|
||||
case filelib:is_dir(TmpDirPath) of
|
||||
true ->
|
||||
throw(?UEX({mkdtemp_failed, file_exists}, "tmp directory exists", []));
|
||||
false ->
|
||||
try
|
||||
ok = mkdir_path(TmpDirPath),
|
||||
TmpDirPath
|
||||
catch
|
||||
_C:E -> throw(?UEX({mkdtemp_failed, E}, ?CHECK_PERMS_MSG, []))
|
||||
end
|
||||
end.
|
||||
|
||||
|
||||
|
@ -297,23 +304,20 @@ hex0(I) -> $0 + I.
|
|||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
setup_test() ->
|
||||
case filelib:is_dir("/tmp/ec_file") of
|
||||
true ->
|
||||
remove("/tmp/ec_file", [recursive]);
|
||||
false ->
|
||||
ok
|
||||
end,
|
||||
mkdir_path("/tmp/ec_file/dir"),
|
||||
?assertMatch(false, is_symlink("/tmp/ec_file/dir")),
|
||||
?assertMatch(true, filelib:is_dir("/tmp/ec_file/dir")).
|
||||
|
||||
Dir = insecure_mkdtemp(),
|
||||
mkdir_path(Dir),
|
||||
?assertMatch(false, is_symlink(Dir)),
|
||||
?assertMatch(true, filelib:is_dir(Dir)).
|
||||
|
||||
md5sum_test() ->
|
||||
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
|
||||
|
||||
file_test() ->
|
||||
TermFile = "/tmp/ec_file/dir/file.term",
|
||||
TermFileCopy = "/tmp/ec_file/dircopy/file.term",
|
||||
Dir = insecure_mkdtemp(),
|
||||
TermFile = filename:join(Dir, "ec_file/dir/file.term"),
|
||||
TermFileCopy = filename:join(Dir, "ec_file/dircopy/file.term"),
|
||||
filelib:ensure_dir(TermFile),
|
||||
filelib:ensure_dir(TermFileCopy),
|
||||
write_term(TermFile, "term"),
|
||||
?assertMatch("term", consult(TermFile)),
|
||||
?assertMatch(<<"\"term\". ">>, read(TermFile)),
|
||||
|
@ -323,11 +327,12 @@ file_test() ->
|
|||
?assertMatch("term", consult(TermFileCopy)).
|
||||
|
||||
teardown_test() ->
|
||||
remove("/tmp/ec_file", [recursive]),
|
||||
?assertMatch(false, filelib:is_dir("/tmp/ec_file")).
|
||||
Dir = insecure_mkdtemp(),
|
||||
remove(Dir, [recursive]),
|
||||
?assertMatch(false, filelib:is_dir(Dir)).
|
||||
|
||||
setup_base_and_target() ->
|
||||
{ok, BaseDir} = ewl_file:create_tmp_dir("/tmp"),
|
||||
BaseDir = insecure_mkdtemp(),
|
||||
DummyContents = <<"This should be deleted">>,
|
||||
SourceDir = filename:join([BaseDir, "source"]),
|
||||
ok = file:make_dir(SourceDir),
|
||||
|
@ -344,17 +349,12 @@ setup_base_and_target() ->
|
|||
|
||||
find_test() ->
|
||||
%% Create a directory in /tmp for the test. Clean everything afterwards
|
||||
{BaseDir, _SourceDir, {Name1, Name2, Name3, _NoName}} = setup_base_and_target(),
|
||||
?assertMatch([Name2,
|
||||
Name3,
|
||||
Name1],
|
||||
find(BaseDir, "file[a-z]+\$")),
|
||||
remove(BaseDir, [recursive]).
|
||||
|
||||
{setup,
|
||||
fun setup_base_and_target/0,
|
||||
fun ({BaseDir, _, _}) ->
|
||||
ewl_file:delete_dir(BaseDir)
|
||||
end,
|
||||
fun ({BaseDir, _, {Name1, Name2, Name3, _}}) ->
|
||||
?assertMatch([Name2,
|
||||
Name3,
|
||||
Name1],
|
||||
ewl_file:find(BaseDir, "file[a-z]+\$"))
|
||||
end}.
|
||||
|
||||
-endif.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: Erlang; fill-column: 75; comment-column: 50; -*-
|
||||
{application, erlware_commons,
|
||||
[{description, "Additional standard library for Erlang"},
|
||||
{vsn, "0.6.2"},
|
||||
{vsn, "0.7.0"},
|
||||
{modules, [
|
||||
ec_talk,
|
||||
ec_lists,
|
Loading…
Add table
Add a link
Reference in a new issue