%% %% Copyright (c) 2014 Kungliga Tekniska Högskolan %% (KTH Royal Institute of Technology, Stockholm, Sweden). %% -module(atomic). -export([replacefile/2, readfile/1]). -spec replacefile(string(), binary()) -> ok. replacefile(Path, Content) -> TempName = util:tempfilename(Path), util:write_tempfile_and_rename(Path, TempName, Content), util:fsync([Path, filename:dirname(Path)]). -spec readfile(string()) -> binary(). readfile(Path) -> case file:read_file(Path) of {ok, Contents} -> Contents; {error, enoent} -> noentry; {error, Error} -> util:exit_with_error(readfile, Error, "Error reading file") end.