summaryrefslogtreecommitdiff
path: root/src/perm.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/perm.erl')
-rw-r--r--src/perm.erl25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/perm.erl b/src/perm.erl
index 34f431c..5cd2889 100644
--- a/src/perm.erl
+++ b/src/perm.erl
@@ -4,7 +4,7 @@
%%
-module(perm).
--export([ensurefile/3]).
+-export([ensurefile/3, readfile/2]).
fsync([]) ->
ok;
@@ -18,14 +18,10 @@ fsync([Name | Rest]) ->
readfile_and_verify(Name, Content) ->
case file:read_file(Name) of
- {ok, ContentsReadBinary} ->
- ContentsRead = binary_to_list(ContentsReadBinary),
- if
- Content == ContentsRead ->
- ok;
- true ->
- differ
- end;
+ {ok, ContentsRead} when Content == ContentsRead ->
+ ok;
+ {ok, _ContentsRead} ->
+ differ;
{error, Error} ->
{error, Error}
end.
@@ -109,3 +105,14 @@ ensurefile(Rootdir, Key, Content) ->
{error, Error} ->
exit_with_error(Error, "Error reading file")
end.
+
+readfile(Rootdir, Key) ->
+ {_Dirs, Path} = path_for_key(Rootdir, Key),
+ case file:read_file(Path) of
+ {ok, Contents} ->
+ Contents;
+ {error, enoent} ->
+ noentry;
+ {error, Error} ->
+ exit_with_error(Error, "Error reading file")
+ end.