remove unnecessary eaccess special casing

It's better to let these errors bubble and/or not give them special
treatment when file:format_error/1 can do a better job of describing
the failure.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/311d0692
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/311d0692
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/311d0692

Branch: refs/heads/1.1.x
Commit: 311d0692b6de8d7b1d62f74f07c488233557b1ac
Parents: 785d32f
Author: Randall Leeds <rand...@apache.org>
Authored: Sun Mar 18 20:19:27 2012 -0700
Committer: Randall Leeds <rand...@apache.org>
Committed: Sun Mar 18 22:10:58 2012 -0700

----------------------------------------------------------------------
 src/couchdb/couch_config.erl        |   11 ++++-------
 src/couchdb/couch_config_writer.erl |    8 +++++---
 src/couchdb/couch_file.erl          |    5 +----
 src/couchdb/couch_log.erl           |    2 --
 src/couchdb/couch_server_sup.erl    |   12 ++++++++++--
 5 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/311d0692/src/couchdb/couch_config.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl
index f669853..44a102d 100644
--- a/src/couchdb/couch_config.erl
+++ b/src/couchdb/couch_config.erl
@@ -187,13 +187,10 @@ parse_ini_file(IniFile) ->
     case file:read_file(IniFilename) of
         {ok, IniBin0} ->
             IniBin0;
-        {error, eacces} ->
-            throw({file_permission_error, IniFile});
-        {error, enoent} ->
-            Fmt = "Couldn't find server configuration file ~s.",
-            Msg = ?l2b(io_lib:format(Fmt, [IniFilename])),
-            ?LOG_ERROR("~s~n", [Msg]),
-            throw({startup_error, Msg})
+        {error, Reason} = Error ->
+            ?LOG_ERROR("Couldn't read server configuration file ~s: ~s",
+                [IniFilename, file:format_error(Reason)]),
+            throw(Error)
     end,
 
     Lines = re:split(IniBin, "\r\n|\n|\r|\032", [{return, list}]),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/311d0692/src/couchdb/couch_config_writer.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_config_writer.erl 
b/src/couchdb/couch_config_writer.erl
index decd269..3a65c37 100644
--- a/src/couchdb/couch_config_writer.erl
+++ b/src/couchdb/couch_config_writer.erl
@@ -22,6 +22,8 @@
 
 -export([save_to_file/2]).
 
+-include("couch_db.hrl").
+
 %% @spec save_to_file(
 %%           Config::{{Section::string(), Option::string()}, Value::string()},
 %%           File::filename()) -> ok
@@ -38,9 +40,9 @@ save_to_file({{Section, Key}, Value}, File) ->
     case file:write_file(File, NewFileContents) of
     ok ->
         ok;
-    {error, eacces} ->
-        {file_permission_error, File};
-    Error ->
+    {error, Reason} = Error ->
+        ?LOG_ERROR("Couldn't write config file ~s: ~s",
+            [File, file:format_error(Reason)]),
         Error
     end.
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/311d0692/src/couchdb/couch_file.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 5c5d51b..b5eed41 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -53,10 +53,7 @@ open(Filepath, Options) ->
             {trap_exit, true} -> receive {'EXIT', Pid, _} -> ok end;
             {trap_exit, false} -> ok
             end,
-            case Error of
-            {error, eacces} -> {file_permission_error, Filepath};
-            _ -> Error
-            end
+            Error
         end;
     Error ->
         Error

http://git-wip-us.apache.org/repos/asf/couchdb/blob/311d0692/src/couchdb/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index ab649ca..397acc7 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -82,8 +82,6 @@ init([]) ->
     case file:open(Filename, [append]) of
     {ok, Fd} ->
         {ok, {Fd, Level, Sasl}};
-    {error, eacces} ->
-        {stop, {file_permission_error, Filename}};
     Error ->
         {stop, Error}
     end.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/311d0692/src/couchdb/couch_server_sup.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_server_sup.erl b/src/couchdb/couch_server_sup.erl
index dd21038..b41e56a 100644
--- a/src/couchdb/couch_server_sup.erl
+++ b/src/couchdb/couch_server_sup.erl
@@ -47,7 +47,9 @@ start_server(IniFiles) ->
     {ok, [PidFile]} ->
         case file:write_file(PidFile, os:getpid()) of
         ok -> ok;
-        Error -> io:format("Failed to write PID file ~s, error: ~p", [PidFile, 
Error])
+        {error, Reason} ->
+            io:format("Failed to write PID file ~s: ~s",
+                [PidFile, file:format_error(Reason)])
         end;
     _ -> ok
     end,
@@ -135,7 +137,13 @@ start_server(IniFiles) ->
             undefined -> [];
             Uri -> io_lib:format("~s~n", [Uri])
             end end || Uri <- Uris],
-        ok = file:write_file(UriFile, Lines)
+        case file:write_file(UriFile, Lines) of
+        ok -> ok;
+        {error, Reason2} = Error ->
+            ?LOG_ERROR("Failed to write to URI file ~s: ~s",
+                [UriFile, file:format_error(Reason2)]),
+            throw(Error)
+        end
     end,
 
     {ok, Pid}.

Reply via email to