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:
Jordan Wilberding 2012-06-05 19:57:58 -04:00
commit 8d625ceb46
5 changed files with 41 additions and 53 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
*.beam
.*
_build _build
erl_crash.dump erl_crash.dump
*.pyc *.pyc

View file

@ -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
View file

@ -0,0 +1,3 @@
{erl_opts,
[debug_info,
warnings_as_errors]}.

View file

@ -9,7 +9,7 @@
-export([ -export([
copy/2, copy/2,
copy/3, copy/3,
mkdtemp/0, insecure_mkdtemp/0,
mkdir_path/1, mkdir_path/1,
find/2, find/2,
is_symlink/1, is_symlink/1,
@ -107,16 +107,23 @@ is_symlink(Path) ->
%% @doc make a unique temorory directory. Similar function to BSD stdlib %% @doc make a unique temorory directory. Similar function to BSD stdlib
%% function of the same name. %% function of the same name.
-spec mkdtemp() -> TmpDirPath::path(). -spec insecure_mkdtemp() -> TmpDirPath::path().
mkdtemp() -> insecure_mkdtemp() ->
UniqueNumber = integer_to_list(element(3, now())), random:seed(now()),
UniqueNumber = erlang:integer_to_list(erlang:trunc(random:uniform() * 1000000000000)),
TmpDirPath = TmpDirPath =
filename:join([tmp(), lists:flatten([".tmp_dir", UniqueNumber])]), filename:join([tmp(), lists:flatten([".tmp_dir", UniqueNumber])]),
try
ok = mkdir_path(TmpDirPath), case filelib:is_dir(TmpDirPath) of
TmpDirPath true ->
catch throw(?UEX({mkdtemp_failed, file_exists}, "tmp directory exists", []));
_C:E -> throw(?UEX({mkdtemp_failed, E}, ?CHECK_PERMS_MSG, [])) false ->
try
ok = mkdir_path(TmpDirPath),
TmpDirPath
catch
_C:E -> throw(?UEX({mkdtemp_failed, E}, ?CHECK_PERMS_MSG, []))
end
end. end.
@ -297,23 +304,20 @@ hex0(I) -> $0 + I.
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
setup_test() -> setup_test() ->
case filelib:is_dir("/tmp/ec_file") of Dir = insecure_mkdtemp(),
true -> mkdir_path(Dir),
remove("/tmp/ec_file", [recursive]); ?assertMatch(false, is_symlink(Dir)),
false -> ?assertMatch(true, filelib:is_dir(Dir)).
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")).
md5sum_test() -> md5sum_test() ->
?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")). ?assertMatch("cfcd208495d565ef66e7dff9f98764da", md5sum("0")).
file_test() -> file_test() ->
TermFile = "/tmp/ec_file/dir/file.term", Dir = insecure_mkdtemp(),
TermFileCopy = "/tmp/ec_file/dircopy/file.term", 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"), write_term(TermFile, "term"),
?assertMatch("term", consult(TermFile)), ?assertMatch("term", consult(TermFile)),
?assertMatch(<<"\"term\". ">>, read(TermFile)), ?assertMatch(<<"\"term\". ">>, read(TermFile)),
@ -323,11 +327,12 @@ file_test() ->
?assertMatch("term", consult(TermFileCopy)). ?assertMatch("term", consult(TermFileCopy)).
teardown_test() -> teardown_test() ->
remove("/tmp/ec_file", [recursive]), Dir = insecure_mkdtemp(),
?assertMatch(false, filelib:is_dir("/tmp/ec_file")). remove(Dir, [recursive]),
?assertMatch(false, filelib:is_dir(Dir)).
setup_base_and_target() -> setup_base_and_target() ->
{ok, BaseDir} = ewl_file:create_tmp_dir("/tmp"), BaseDir = insecure_mkdtemp(),
DummyContents = <<"This should be deleted">>, DummyContents = <<"This should be deleted">>,
SourceDir = filename:join([BaseDir, "source"]), SourceDir = filename:join([BaseDir, "source"]),
ok = file:make_dir(SourceDir), ok = file:make_dir(SourceDir),
@ -344,17 +349,12 @@ setup_base_and_target() ->
find_test() -> find_test() ->
%% Create a directory in /tmp for the test. Clean everything afterwards %% 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. -endif.

View file

@ -1,7 +1,7 @@
%% -*- mode: Erlang; fill-column: 75; comment-column: 50; -*- %% -*- mode: Erlang; fill-column: 75; comment-column: 50; -*-
{application, erlware_commons, {application, erlware_commons,
[{description, "Additional standard library for Erlang"}, [{description, "Additional standard library for Erlang"},
{vsn, "0.6.2"}, {vsn, "0.7.0"},
{modules, [ {modules, [
ec_talk, ec_talk,
ec_lists, ec_lists,