From bdd5d902d9e66cd466a86c94d9484e68d637f888 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 29 Nov 2014 11:06:43 -0600 Subject: fix lock provider to work anytime it is run --- src/rebar_fetch.erl | 66 ++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'src/rebar_fetch.erl') diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl index e763c2c..933b626 100644 --- a/src/rebar_fetch.erl +++ b/src/rebar_fetch.erl @@ -19,52 +19,40 @@ -spec lock_source(file:filename_all(), rebar_resource:resource()) -> rebar_resource:resource() | {error, string()}. lock_source(AppDir, Source) -> - case get_resource_type(Source) of - {error, _}=Error -> - Error; - Module -> - Module:lock(AppDir, Source) - end. + Module = get_resource_type(Source), + Module:lock(AppDir, Source). -spec download_source(file:filename_all(), rebar_resource:resource()) -> true | {error, any()}. download_source(AppDir, Source) -> - case get_resource_type(Source) of - {error, _}=Error -> - Error; - Module -> - TmpDir = ec_file:insecure_mkdtemp(), - AppDir1 = ec_cnv:to_list(AppDir), - ec_file:mkdir_p(AppDir1), - case Module:download(TmpDir, Source) of - {ok, _} -> - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), - true; - {tarball, File} -> - ok = erl_tar:extract(File, [{cwd, TmpDir} - ,compressed]), - BaseName = filename:basename(AppDir1), - [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), - true - end + Module = get_resource_type(Source), + TmpDir = ec_file:insecure_mkdtemp(), + AppDir1 = ec_cnv:to_list(AppDir), + ec_file:mkdir_p(AppDir1), + case Module:download(TmpDir, Source) of + {ok, _} -> + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), + true; + {tarball, File} -> + ok = erl_tar:extract(File, [{cwd, TmpDir} + ,compressed]), + BaseName = filename:basename(AppDir1), + [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), + true end. -spec needs_update(file:filename_all(), rebar_resource:resource()) -> boolean() | {error, string()}. needs_update(AppDir, Source) -> - case get_resource_type(Source) of - {error, _}=Error -> - Error; - Module -> - try - Module:needs_update(AppDir, Source) - catch - _:_ -> - true - end + Module = get_resource_type(Source), + try + Module:needs_update(AppDir, Source) + catch + _:_ -> + true end. get_resource_type({Type, Location}) -> -- cgit v1.1 From 5673fe035da48d48d0824bf7260bfda28c55c9d5 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 30 Nov 2014 21:12:02 -0600 Subject: fixes for dialyzer findings --- src/rebar_fetch.erl | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/rebar_fetch.erl') diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl index 933b626..2df892c 100644 --- a/src/rebar_fetch.erl +++ b/src/rebar_fetch.erl @@ -24,25 +24,30 @@ lock_source(AppDir, Source) -> -spec download_source(file:filename_all(), rebar_resource:resource()) -> true | {error, any()}. download_source(AppDir, Source) -> - Module = get_resource_type(Source), - TmpDir = ec_file:insecure_mkdtemp(), - AppDir1 = ec_cnv:to_list(AppDir), - ec_file:mkdir_p(AppDir1), - case Module:download(TmpDir, Source) of - {ok, _} -> - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), - true; - {tarball, File} -> - ok = erl_tar:extract(File, [{cwd, TmpDir} - ,compressed]), - BaseName = filename:basename(AppDir1), - [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), - true + try + Module = get_resource_type(Source), + TmpDir = ec_file:insecure_mkdtemp(), + AppDir1 = ec_cnv:to_list(AppDir), + ec_file:mkdir_p(AppDir1), + case Module:download(TmpDir, Source) of + {ok, _} -> + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), + true; + {tarball, File} -> + ok = erl_tar:extract(File, [{cwd, TmpDir} + ,compressed]), + BaseName = filename:basename(AppDir1), + [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), + true + end + catch + _:E -> + {error, E} end. -spec needs_update(file:filename_all(), rebar_resource:resource()) -> boolean() | {error, string()}. -- cgit v1.1