summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-12 13:05:59 +0100
committerw0rp <devw0rp@gmail.com>2018-07-12 13:05:59 +0100
commitac0abc7c1fb1150edc4359e1a86c2a22e95de71c (patch)
treeebe0ff7cd658568a35900b0e39bbeaeab6c2d655 /autoload
parent6ef31073dd8f8d094ef7bc5e7152a576ef4f9064 (diff)
downloadale-ac0abc7c1fb1150edc4359e1a86c2a22e95de71c.zip
Fix #1716 - Replace tempdir() with a wrapper to preserve TMPDIR
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/command.vim2
-rw-r--r--autoload/ale/engine.vim2
-rw-r--r--autoload/ale/handlers/haskell.vim2
-rw-r--r--autoload/ale/path.vim2
-rw-r--r--autoload/ale/util.vim19
5 files changed, 23 insertions, 4 deletions
diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim
index b4bf3794..543c9953 100644
--- a/autoload/ale/command.vim
+++ b/autoload/ale/command.vim
@@ -13,7 +13,7 @@ function! s:TemporaryFilename(buffer) abort
" Create a temporary filename, <temp_dir>/<original_basename>
" The file itself will not be created by this function.
- return tempname() . (has('win32') ? '\' : '/') . l:filename
+ return ale#util#Tempname() . (has('win32') ? '\' : '/') . l:filename
endfunction
" Given a command string, replace every...
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index a64d8f9f..c644e63f 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -98,7 +98,7 @@ endfunction
" Create a new temporary directory and manage it in one go.
function! ale#engine#CreateDirectory(buffer) abort
- let l:temporary_directory = tempname()
+ let l:temporary_directory = ale#util#Tempname()
" Create the temporary directory for the file, unreadable by 'other'
" users.
call mkdir(l:temporary_directory, '', 0750)
diff --git a/autoload/ale/handlers/haskell.vim b/autoload/ale/handlers/haskell.vim
index 8a0d0013..9223b650 100644
--- a/autoload/ale/handlers/haskell.vim
+++ b/autoload/ale/handlers/haskell.vim
@@ -2,7 +2,7 @@
" Description: Error handling for the format GHC outputs.
" Remember the directory used for temporary files for Vim.
-let s:temp_dir = fnamemodify(tempname(), ':h')
+let s:temp_dir = fnamemodify(ale#util#Tempname(), ':h')
" Build part of a regular expression for matching ALE temporary filenames.
let s:temp_regex_prefix =
\ '\M'
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 91832b35..45da3709 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -84,7 +84,7 @@ function! ale#path#IsAbsolute(filename) abort
return a:filename[:0] is# '/' || a:filename[1:2] is# ':\'
endfunction
-let s:temp_dir = ale#path#Simplify(fnamemodify(tempname(), ':h'))
+let s:temp_dir = ale#path#Simplify(fnamemodify(ale#util#Tempname(), ':h'))
" Given a filename, return 1 if the file represents some temporary file
" created by Vim.
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 267b0587..93b997ea 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -277,6 +277,25 @@ function! ale#util#InSandbox() abort
return 0
endfunction
+function! ale#util#Tempname() abort
+ let l:clear_tempdir = 0
+
+ if has('unix') && empty($TMPDIR)
+ let l:clear_tempdir = 1
+ let $TMPDIR = '/tmp'
+ endif
+
+ try
+ let l:name = tempname() " no-custom-checks
+ finally
+ if l:clear_tempdir
+ let $TMPDIR = ''
+ endif
+ endtry
+
+ return l:name
+endfunction
+
" Given a single line, or a List of lines, and a single pattern, or a List
" of patterns, return all of the matches for the lines(s) from the given
" patterns, using matchlist().