add exists to ec_file
Signed-off-by: Jordan Wilberding <diginux@gmail.com>
This commit is contained in:
parent
a9f2a771f0
commit
f77afd43c3
1 changed files with 20 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
-module(ec_file).
|
-module(ec_file).
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
|
exists/1,
|
||||||
copy/2,
|
copy/2,
|
||||||
copy/3,
|
copy/3,
|
||||||
insecure_mkdtemp/0,
|
insecure_mkdtemp/0,
|
||||||
|
@ -40,6 +41,15 @@
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
-spec exists(file:filename()) -> boolean().
|
||||||
|
exists(Filename) ->
|
||||||
|
case file:read_file_info(Filename) of
|
||||||
|
{ok, _} ->
|
||||||
|
true;
|
||||||
|
{error, _Reason} ->
|
||||||
|
false
|
||||||
|
end.
|
||||||
|
|
||||||
%% @doc copy an entire directory to another location.
|
%% @doc copy an entire directory to another location.
|
||||||
-spec copy(file:name(), file:name(), Options::[option()]) -> ok | {error, Reason::term()}.
|
-spec copy(file:name(), file:name(), Options::[option()]) -> ok | {error, Reason::term()}.
|
||||||
copy(From, To, []) ->
|
copy(From, To, []) ->
|
||||||
|
@ -314,6 +324,16 @@ setup_base_and_target() ->
|
||||||
ok = file:write_file(NoName, DummyContents),
|
ok = file:write_file(NoName, DummyContents),
|
||||||
{BaseDir, SourceDir, {Name1, Name2, Name3, NoName}}.
|
{BaseDir, SourceDir, {Name1, Name2, Name3, NoName}}.
|
||||||
|
|
||||||
|
exists_test() ->
|
||||||
|
BaseDir = insecure_mkdtemp(),
|
||||||
|
SourceDir = filename:join([BaseDir, "source1"]),
|
||||||
|
NoName = filename:join([SourceDir, "noname"]),
|
||||||
|
ok = file:make_dir(SourceDir),
|
||||||
|
Name1 = filename:join([SourceDir, "fileone"]),
|
||||||
|
ok = file:write_file(Name1, <<"Testn">>),
|
||||||
|
?assertMatch(true, exists(Name1)),
|
||||||
|
?assertMatch(false, exists(NoName)).
|
||||||
|
|
||||||
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(),
|
{BaseDir, _SourceDir, {Name1, Name2, Name3, _NoName}} = setup_base_and_target(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue