summaryrefslogtreecommitdiff
path: root/src/rebar_fetch.erl
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2014-12-02 15:55:51 -0600
committerTristan Sloughter <tristan.sloughter@gmail.com>2014-12-02 15:55:51 -0600
commit3b2d9ba8c81a41ae5cd554a3f50283e713e191c8 (patch)
treef5309346fc164fe3556e96db679b32bf5eca5a56 /src/rebar_fetch.erl
parent8d655d3c502295394ab30d9fc3fd11679629885d (diff)
parent3af351cec28521caaa15308b1a4a992380723794 (diff)
Merge pull request #31 from tsloughter/profiles
Profiles
Diffstat (limited to 'src/rebar_fetch.erl')
-rw-r--r--src/rebar_fetch.erl71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl
index e763c2c..2df892c 100644
--- a/src/rebar_fetch.erl
+++ b/src/rebar_fetch.erl
@@ -19,52 +19,45 @@
-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
+ 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()}.
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}) ->