diff options
author | Tristan Sloughter <t@crashfast.com> | 2014-11-14 16:08:12 -0600 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2014-11-15 09:21:11 -0600 |
commit | 4c8db4e047c8a6bda12534fb82562ff6b6c11d1f (patch) | |
tree | d0a112efbd8f66c68381fea9a487660b7166e702 /src | |
parent | 731c3fd8a43b49e7d47127c743160705f776ce40 (diff) |
write packages file to tmp so a lost connection doesn't mean corruption
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_update.erl | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index ce6350b..e57f19d 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -35,11 +35,14 @@ do(State) -> ?INFO("Updating package index...", []), try Url = url(State), + TmpDir = ec_file:insecure_mkdtemp(), + TmpFile = filename:join(TmpDir, "packages"), Home = rebar_utils:home_dir(), PackagesFile = filename:join([Home, ?CONFIG_DIR, "packages"]), filelib:ensure_dir(PackagesFile), - {ok, _RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} - ,{sync, true}]) + {ok, _RequestId} = httpc:request(get, {Url, []}, [], [{stream, TmpFile} + ,{sync, true}]), + ok = ec_file:copy(TmpFile, PackagesFile) catch _:_ -> {error, {?MODULE, package_index_write}} |