aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2016-03-17 15:30:28 +0100
committerBjörn-Egil Dahlberg <[email protected]>2016-03-17 15:30:28 +0100
commit77ae8d93402b40aa781387831adf6271caa491a4 (patch)
tree4d9dff98727af55b811298af7f505c88d30341c9
parent586e8f0cb587355221ed8a24c4e8ca06e8404192 (diff)
downloadotp-77ae8d93402b40aa781387831adf6271caa491a4.tar.gz
otp-77ae8d93402b40aa781387831adf6271caa491a4.tar.bz2
otp-77ae8d93402b40aa781387831adf6271caa491a4.zip
stdlib: Fix filename:basedir/2,3
Handle the case when the environment APPDATA is not set.
-rw-r--r--lib/stdlib/src/filename.erl39
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl
index d921a69108..37f87b1ff9 100644
--- a/lib/stdlib/src/filename.erl
+++ b/lib/stdlib/src/filename.erl
@@ -1068,24 +1068,43 @@ basedir_darwin(Type) ->
%% user_cache %LOCALAPPDATA%[/$author]/$appname[/$version]/Cache
%% user_log %LOCALAPPDATA%[/$author]/$appname[/$version]/Logs
+-define(basedir_windows_user_data, "Local").
+-define(basedir_windows_user_config, "Roaming").
+-define(basedir_windows_user_cache, "Local"). %% Cache is added later
+-define(basedir_windows_user_log, "Local"). %% Logs is added later
+
basedir_windows(Type) ->
%% If LOCALAPPDATA is not defined we are likely on an
%% XP machine. Use APPDATA instead.
- AppData = basedir_windows_appdata(),
- case Type of
- user_data -> getenv("LOCALAPPDATA", AppData);
- user_config -> AppData;
- user_cache -> getenv("LOCALAPPDATA", AppData);
- user_log -> getenv("LOCALAPPDATA", AppData);
- site_data -> [];
- site_config -> []
+ case basedir_windows_appdata() of
+ noappdata ->
+ %% No AppData is set
+ %% Probably running MSYS
+ case Type of
+ user_data -> basedir_join_home(?basedir_windows_user_data);
+ user_config -> basedir_join_home(?basedir_windows_user_config);
+ user_cache -> basedir_join_home(?basedir_windows_user_cache);
+ user_log -> basedir_join_home(?basedir_windows_user_log);
+ site_data -> [];
+ site_config -> []
+ end;
+ {ok, AppData} ->
+ case Type of
+ user_data -> getenv("LOCALAPPDATA", AppData);
+ user_config -> AppData;
+ user_cache -> getenv("LOCALAPPDATA", AppData);
+ user_log -> getenv("LOCALAPPDATA", AppData);
+ site_data -> [];
+ site_config -> []
+ end
end.
basedir_windows_appdata() ->
case os:getenv("APPDATA") of
Invalid when Invalid =:= false orelse Invalid =:= [] ->
- erlang:error(noappdata);
- Val -> Val
+ noappdata;
+ Val ->
+ {ok, Val}
end.
%% basedir aux