summaryrefslogtreecommitdiff
path: root/src/perm.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/perm.erl')
-rw-r--r--src/perm.erl13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/perm.erl b/src/perm.erl
index 466cc4f..9f02b55 100644
--- a/src/perm.erl
+++ b/src/perm.erl
@@ -49,25 +49,32 @@ path_for_key(Rootdir, Key) ->
-spec ensurefile(string(), binary(), binary()) -> ok | differ.
ensurefile(Rootdir, Key, Content) ->
+ lager:debug("dir ~p key ~p", [Rootdir, Key]),
{Dirs, Path} = path_for_key(Rootdir, Key),
case readfile_and_verify(Path, Content) of
ok ->
- util:fsync([Path, Rootdir | Dirs]);
+ lager:debug("key ~p existed, fsync", [Key]),
+ util:fsync([Path, Rootdir | Dirs]),
+ lager:debug("key ~p fsynced", [Key]);
differ ->
+ lager:debug("key ~p existed, was different", [Key]),
differ;
{error, enoent} ->
+ lager:debug("key ~p didn't exist, add", [Key]),
util:check_error(make_dirs([Rootdir, Rootdir ++ "nursery/"]
++ Dirs),
makedir, "Error creating directory"),
NurseryName = Rootdir ++ "nursery/" ++
util:tempfilename(hex:bin_to_hexstr(Key)),
util:write_tempfile_and_rename(Path, NurseryName, Content),
- util:fsync([Path, Rootdir | Dirs]);
+ lager:debug("key ~p added, fsync", [Key]),
+ util:fsync([Path, Rootdir | Dirs]),
+ lager:debug("key ~p fsynced", [Key]);
{error, Error} ->
util:exit_with_error(Error, readfile, "Error reading file")
end.
--spec readfile(string(), binary()) -> binary().
+-spec readfile(string(), binary()) -> binary() | noentry.
readfile(Rootdir, Key) ->
{_Dirs, Path} = path_for_key(Rootdir, Key),
atomic:readfile(Path).