LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File erlang-history-path-unix.patch of Package erlang-history (Project home:Ledest:erlang)

diff -Ndurp erlang-history/src/5.2/group_history.erl erlang-history-path-unix/src/5.2/group_history.erl
--- erlang-history/src/5.2/group_history.erl	2017-04-30 17:36:38.000000000 +0300
+++ erlang-history-path-unix/src/5.2/group_history.erl	2017-06-01 04:01:50.189183753 +0300
@@ -3,10 +3,10 @@
 
 %% Make a minimal size that should encompass set of lines and then make
 %% a file rotation for N files of this size.
--define(DEFAULT_HISTORY_FILE, ".erlang-history/log").
+-define(DEFAULT_HISTORY_FILE, "erlang-shell-log").
 -define(MAX_HISTORY_FILES, 10).
 -define(DEFAULT_SIZE, 1024*512). % 512 kb total default
--define(DEFAULT_STATUS, enabled).
+-define(DEFAULT_STATUS, disabled).
 -define(MIN_HISTORY_SIZE, (50*1024)). % 50 kb, in bytes
 -define(DEFAULT_DROP, []).
 -define(DISK_LOG_FORMAT, internal). % since we want repairs
@@ -158,12 +158,18 @@ matches_log(Txt) ->
 %% Return whether the shell history is enabled or not
 -spec history_status() -> enabled | disabled.
 history_status() ->
-    case application:get_env(kernel, shell_history) of
+    case is_user() orelse application:get_env(kernel, shell_history) of
+        true -> disabled; % don't run for user proc
         {ok, enabled} -> enabled;
         undefined -> ?DEFAULT_STATUS;
         _ -> disabled
     end.
 
+%% Return whether the user process is running this
+-spec is_user() -> boolean().
+is_user() ->
+    process_info(self(), registered_name) =:= {registered_name, user}.
+
 %% Open a disk_log file while ensuring the required path is there.
 open_log() ->
     Opts = log_options(),
@@ -175,8 +181,8 @@ log_options() -> log_options(false).
 
 %% Return logger options (with repairs configurable)
 log_options(Repair) ->
-    Home = home(),
-    File = filename:join([Home, ?DEFAULT_HISTORY_FILE]),
+    Path = find_path(),
+    File = filename:join([Path, ?DEFAULT_HISTORY_FILE]),
     Size = find_wrap_values(),
     [{name, ?LOG_NAME},
      {file, File},
@@ -187,6 +193,7 @@ log_options(Repair) ->
      {distributed, []},
      {notify, false},
      {head, {vsn, ?VSN}},
+     {quiet, true},
      {mode, read_write}].
 
 -spec ensure_path([{file, string()} | {atom(), _}, ...]) -> ok | {error, term()}.
@@ -306,13 +313,18 @@ disable_history() ->
     show('$#erlang-history-disable', "Disabling shell history logging.~n", []),
     application:set_env(kernel, shell_history, force_disabled).
 
-home() ->
-    case init:get_argument(home) of
-        {ok, [[Home]]} ->
-            Home;
-        _ ->
-            error_logger:error_msg("No home directory found"),
-            error(badarg)
+find_path() ->
+    case application:get_env(kernel, shell_history_path) of
+        undefined -> filename:join(case os:getenv("XDG_CACHE_HOME", "") of
+                                       "" -> filename:join(case os:getenv("HOME") of
+                                                               false ->
+                                                                   {ok, [[Home]]} = init:get_argument(home),
+                                                                   Home;
+                                                               Home -> Home
+                                                           end, ".cache");
+                                       Home -> Home
+                                   end, "erlang-history");
+        {ok, Path} -> Path
     end.
 
 to_drop() ->