mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
XDG: Windows: resolve $LOCALAPPDATA, $TEMP (#5278)
After #4964 environment variables in the XDG "fallback" table are no longer expanded. Fallback to correctly expanded $LOCALAPPDATA, $TEMP. If that fails (unlikely), fallback to hard-coded paths (e.g. ~/AppData/Local). Closes #5255
This commit is contained in:
parent
ca7a5c0ce7
commit
32156f06f7
@ -16,20 +16,29 @@ static const char *xdg_env_vars[] = {
|
||||
[kXDGDataDirs] = "XDG_DATA_DIRS",
|
||||
};
|
||||
|
||||
#ifdef WIN32
|
||||
static const char *const xdg_defaults_env_vars[] = {
|
||||
[kXDGConfigHome] = "LOCALAPPDATA",
|
||||
[kXDGDataHome] = "LOCALAPPDATA",
|
||||
[kXDGCacheHome] = "TEMP",
|
||||
[kXDGRuntimeDir] = NULL,
|
||||
[kXDGConfigDirs] = NULL,
|
||||
[kXDGDataDirs] = NULL,
|
||||
};
|
||||
#endif
|
||||
|
||||
/// Defaults for XDGVarType values
|
||||
///
|
||||
/// Used in case environment variables contain nothing. Need to be expanded.
|
||||
static const char *const xdg_defaults[] = {
|
||||
#ifdef WIN32
|
||||
// Windows
|
||||
[kXDGConfigHome] = "$LOCALAPPDATA",
|
||||
[kXDGDataHome] = "$LOCALAPPDATA",
|
||||
[kXDGCacheHome] = "$TEMP",
|
||||
[kXDGConfigHome] = "~\\AppData\\Local",
|
||||
[kXDGDataHome] = "~\\AppData\\Local",
|
||||
[kXDGCacheHome] = "~\\AppData\\Local\\Temp",
|
||||
[kXDGRuntimeDir] = NULL,
|
||||
[kXDGConfigDirs] = NULL,
|
||||
[kXDGDataDirs] = NULL,
|
||||
#else
|
||||
// Linux, BSD, CYGWIN, Apple
|
||||
[kXDGConfigHome] = "~/.config",
|
||||
[kXDGDataHome] = "~/.local/share",
|
||||
[kXDGCacheHome] = "~/.cache",
|
||||
@ -50,7 +59,14 @@ char *stdpaths_get_xdg_var(const XDGVarType idx)
|
||||
const char *const env = xdg_env_vars[idx];
|
||||
const char *const fallback = xdg_defaults[idx];
|
||||
|
||||
const char *const env_val = os_getenv(env);
|
||||
const char *env_val = os_getenv(env);
|
||||
|
||||
#ifdef WIN32
|
||||
if (env_val == NULL) {
|
||||
env_val = os_getenv(xdg_defaults_env_vars[idx]);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *ret = NULL;
|
||||
if (env_val != NULL) {
|
||||
ret = xstrdup(env_val);
|
||||
|
@ -9,8 +9,6 @@ local eval = helpers.eval
|
||||
local eq = helpers.eq
|
||||
local neq = helpers.neq
|
||||
|
||||
if helpers.pending_win32(pending) then return end
|
||||
|
||||
local function init_session(...)
|
||||
local args = { helpers.nvim_prog, '-i', 'NONE', '--embed',
|
||||
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
|
||||
@ -24,6 +22,8 @@ end
|
||||
|
||||
describe('startup defaults', function()
|
||||
describe(':filetype', function()
|
||||
if helpers.pending_win32(pending) then return end
|
||||
|
||||
local function expect_filetype(expected)
|
||||
local screen = Screen.new(48, 4)
|
||||
screen:attach()
|
||||
@ -99,8 +99,37 @@ describe('startup defaults', function()
|
||||
end)
|
||||
|
||||
describe('XDG-based defaults', function()
|
||||
-- Need to be in separate describe() block to not run clear() twice.
|
||||
-- Need separate describe() blocks to not run clear() twice.
|
||||
-- Do not put before_each() here for the same reasons.
|
||||
|
||||
describe('with empty/broken environment', function()
|
||||
it('sets correct defaults', function()
|
||||
clear({env={
|
||||
XDG_CONFIG_HOME=nil,
|
||||
XDG_DATA_HOME=nil,
|
||||
XDG_CACHE_HOME=nil,
|
||||
XDG_RUNTIME_DIR=nil,
|
||||
XDG_CONFIG_DIRS=nil,
|
||||
XDG_DATA_DIRS=nil,
|
||||
LOCALAPPDATA=nil,
|
||||
HOMEPATH=nil,
|
||||
HOMEDRIVE=nil,
|
||||
HOME=nil,
|
||||
TEMP=nil,
|
||||
VIMRUNTIME=nil,
|
||||
USER=nil,
|
||||
}})
|
||||
|
||||
eq('.', meths.get_option('backupdir'))
|
||||
eq('.', meths.get_option('viewdir'))
|
||||
eq('.', meths.get_option('directory'))
|
||||
eq('.', meths.get_option('undodir'))
|
||||
end)
|
||||
end)
|
||||
|
||||
-- TODO(jkeyes): tests below fail on win32 because of path separator.
|
||||
if helpers.pending_win32(pending) then return end
|
||||
|
||||
describe('with too long XDG variables', function()
|
||||
before_each(function()
|
||||
clear({env={
|
||||
|
Loading…
Reference in New Issue
Block a user