Author: fdmanana
Date: Fri Jan  7 11:43:46 2011
New Revision: 1056275

URL: http://svn.apache.org/viewvc?rev=1056275&view=rev
Log:
Merged revision 1056274 from trunk

More explicit and helpful file access permission errors

Closes COUCHDB-966


Modified:
    couchdb/branches/1.1.x/src/couchdb/couch_config.erl
    couchdb/branches/1.1.x/src/couchdb/couch_config_writer.erl
    couchdb/branches/1.1.x/src/couchdb/couch_event_sup.erl
    couchdb/branches/1.1.x/src/couchdb/couch_file.erl
    couchdb/branches/1.1.x/src/couchdb/couch_httpd_misc_handlers.erl
    couchdb/branches/1.1.x/src/couchdb/couch_log.erl

Modified: couchdb/branches/1.1.x/src/couchdb/couch_config.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_config.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_config.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_config.erl Fri Jan  7 11:43:46 2011
@@ -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
         _ ->
             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

Modified: couchdb/branches/1.1.x/src/couchdb/couch_config_writer.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_config_writer.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_config_writer.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_config_writer.erl Fri Jan  7 
11:43:46 2011
@@ -35,7 +35,14 @@ save_to_file({{Section, Key}, Value}, Fi
 
     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) ->

Modified: couchdb/branches/1.1.x/src/couchdb/couch_event_sup.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_event_sup.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_event_sup.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_event_sup.erl Fri Jan  7 11:43:46 
2011
@@ -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.

Modified: couchdb/branches/1.1.x/src/couchdb/couch_file.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_file.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_file.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_file.erl Fri Jan  7 11:43:46 2011
@@ -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

Modified: couchdb/branches/1.1.x/src/couchdb/couch_httpd_misc_handlers.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_httpd_misc_handlers.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_httpd_misc_handlers.erl Fri Jan  7 
11:43:46 2011
@@ -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

Modified: couchdb/branches/1.1.x/src/couchdb/couch_log.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_log.erl?rev=1056275&r1=1056274&r2=1056275&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_log.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_log.erl Fri Jan  7 11:43:46 2011
@@ -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.


Reply via email to