summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2011-01-07 11:43:46 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2011-01-07 11:43:46 +0000
commitc73a8da174f846e5fa401a25c47cb452f9a8bca6 (patch)
tree75b9293bcfd5c12735597095182c88b82bb98366 /src/couchdb
parentb82a37b821b6b943470fcc4476b5530cb48ef4ab (diff)
Merged revision 1056274 from trunk
More explicit and helpful file access permission errors Closes COUCHDB-966 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1056275 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_config.erl19
-rw-r--r--src/couchdb/couch_config_writer.erl9
-rw-r--r--src/couchdb/couch_event_sup.erl8
-rw-r--r--src/couchdb/couch_file.erl5
-rw-r--r--src/couchdb/couch_httpd_misc_handlers.erl8
-rw-r--r--src/couchdb/couch_log.erl10
6 files changed, 44 insertions, 15 deletions
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl
index be53e3a3..34bb97fa 100644
--- a/src/couchdb/couch_config.erl
+++ b/src/couchdb/couch_config.erl
@@ -112,8 +112,7 @@ handle_call(all, _From, Config) ->
Resp = lists:sort((ets:tab2list(?MODULE))),
{reply, Resp, Config};
handle_call({set, Sec, Key, Val, Persist}, From, Config) ->
- true = ets:insert(?MODULE, {{Sec, Key}, Val}),
- case {Persist, Config#config.write_filename} of
+ Result = case {Persist, Config#config.write_filename} of
{true, undefined} ->
ok;
{true, FileName} ->
@@ -121,11 +120,17 @@ handle_call({set, Sec, Key, Val, Persist}, From, Config) ->
_ ->
ok
end,
- spawn_link(fun() ->
- [catch F(Sec, Key, Val, Persist) || {_Pid, F} <- Config#config.notify_funs],
- gen_server:reply(From, ok)
- end),
- {noreply, Config};
+ case Result of
+ ok ->
+ true = ets:insert(?MODULE, {{Sec, Key}, Val}),
+ spawn_link(fun() ->
+ [catch F(Sec, Key, Val, Persist) || {_Pid, F} <- Config#config.notify_funs],
+ gen_server:reply(From, ok)
+ end),
+ {noreply, Config};
+ _Error ->
+ {reply, Result, Config}
+ end;
handle_call({delete, Sec, Key, Persist}, From, Config) ->
true = ets:delete(?MODULE, {Sec,Key}),
case {Persist, Config#config.write_filename} of
diff --git a/src/couchdb/couch_config_writer.erl b/src/couchdb/couch_config_writer.erl
index c8691d79..decd269a 100644
--- a/src/couchdb/couch_config_writer.erl
+++ b/src/couchdb/couch_config_writer.erl
@@ -35,7 +35,14 @@ save_to_file({{Section, Key}, Value}, File) ->
NewLines = process_file_lines(Lines, [], SectionLine, Pattern, Key, Value),
NewFileContents = reverse_and_add_newline(strip_empty_lines(NewLines), []),
- ok = file:write_file(File, NewFileContents).
+ case file:write_file(File, NewFileContents) of
+ ok ->
+ ok;
+ {error, eacces} ->
+ {file_permission_error, File};
+ Error ->
+ Error
+ end.
process_file_lines([Section|Rest], SeenLines, Section, Pattern, Key, Value) ->
diff --git a/src/couchdb/couch_event_sup.erl b/src/couchdb/couch_event_sup.erl
index 6fd6963a..07c48790 100644
--- a/src/couchdb/couch_event_sup.erl
+++ b/src/couchdb/couch_event_sup.erl
@@ -50,8 +50,12 @@ stop(Pid) ->
gen_server:cast(Pid, stop).
init({EventMgr, EventHandler, Args}) ->
- ok = gen_event:add_sup_handler(EventMgr, EventHandler, Args),
- {ok, {EventMgr, EventHandler}}.
+ case gen_event:add_sup_handler(EventMgr, EventHandler, Args) of
+ ok ->
+ {ok, {EventMgr, EventHandler}};
+ {stop, Error} ->
+ {stop, Error}
+ end.
terminate(_Reason, _State) ->
ok.
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 56ebc4f2..7b677034 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -53,7 +53,10 @@ open(Filepath, Options) ->
{trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end;
{trap_exit, false} -> ok
end,
- Error
+ case Error of
+ {error, eacces} -> {file_permission_error, Filepath};
+ _ -> Error
+ end
end;
Error ->
Error
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
index 6cc48f51..213cbfd4 100644
--- a/src/couchdb/couch_httpd_misc_handlers.erl
+++ b/src/couchdb/couch_httpd_misc_handlers.erl
@@ -236,8 +236,12 @@ handle_config_req(Req) ->
handle_approved_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Req, Persist) ->
Value = couch_httpd:json_body(Req),
OldValue = couch_config:get(Section, Key, ""),
- ok = couch_config:set(Section, Key, ?b2l(Value), Persist),
- send_json(Req, 200, list_to_binary(OldValue));
+ case couch_config:set(Section, Key, ?b2l(Value), Persist) of
+ ok ->
+ send_json(Req, 200, list_to_binary(OldValue));
+ Error ->
+ throw(Error)
+ end;
% DELETE /_config/Section/Key
handle_approved_config_req(#httpd{method='DELETE',path_parts=[_,Section,Key]}=Req, Persist) ->
case couch_config:get(Section, Key, null) of
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index dfd2d178..3b6ce97c 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -65,8 +65,14 @@ init([]) ->
end,
ets:insert(?MODULE, {level, Level}),
- {ok, Fd} = file:open(Filename, [append]),
- {ok, {Fd, Level, Sasl}}.
+ case file:open(Filename, [append]) of
+ {ok, Fd} ->
+ {ok, {Fd, Level, Sasl}};
+ {error, eacces} ->
+ {stop, {file_permission_error, Filename}};
+ Error ->
+ {stop, Error}
+ end.
debug_on() ->
get_level_integer() =< ?LEVEL_DEBUG.