From 4c8db4e047c8a6bda12534fb82562ff6b6c11d1f Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 14 Nov 2014 16:08:12 -0600 Subject: write packages file to tmp so a lost connection doesn't mean corruption --- src/rebar_prv_update.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') 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}} -- cgit v1.1