aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2011-03-28 11:12:28 +0200
committerSiri Hansen <[email protected]>2011-03-28 11:12:28 +0200
commit9f78db422a8facfaad909a656ffabeb27f8fe2fd (patch)
treeb0dd4c99bee467cef95accafc141c56cab161894 /lib/stdlib/src
parentf0e2f0b91ac4d45a64ddac511e0eba9b6ce01e92 (diff)
parent07cca90aadc77bad241a378c560a3b4f22352160 (diff)
downloadotp-9f78db422a8facfaad909a656ffabeb27f8fe2fd.tar.gz
otp-9f78db422a8facfaad909a656ffabeb27f8fe2fd.tar.bz2
otp-9f78db422a8facfaad909a656ffabeb27f8fe2fd.zip
Merge branch 'siri/stdlib/log_mf_h-write-index-atomically/OTP-9148' into dev
* siri/stdlib/log_mf_h-write-index-atomically/OTP-9148: Update index file atomically
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/log_mf_h.erl14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/stdlib/src/log_mf_h.erl b/lib/stdlib/src/log_mf_h.erl
index 2729f27e51..5fa5360fa1 100644
--- a/lib/stdlib/src/log_mf_h.erl
+++ b/lib/stdlib/src/log_mf_h.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2009. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -185,13 +185,19 @@ read_index_file(Dir) ->
%%-----------------------------------------------------------------
%% Write the index file. This file contains one binary with
%% the last used filename (an integer).
+%% Write a temporary file and rename it in order to make the update
+%% atomic.
%%-----------------------------------------------------------------
write_index_file(Dir, Index) ->
- case file:open(Dir ++ "/index", [raw, write]) of
+ File = Dir ++ "/index",
+ TmpFile = File ++ ".tmp",
+ case file:open(TmpFile, [raw, write]) of
{ok, Fd} ->
- file:write(Fd, [Index]),
- ok = file:close(Fd);
+ ok = file:write(Fd, [Index]),
+ ok = file:close(Fd),
+ ok = file:rename(TmpFile,File),
+ ok;
_ -> exit(open_index_file)
end.