syl20bnr/spacemacs

Issues with $TMPDIR on macOS

Closed this issue · 3 comments

Description :octocat:

Various functionality is broken because Spacemacs is trying to use a wrong temp directory

Reproduction guide 🪲

  • Start Emacs
  • M-x server-start
  • a permission denied while creating a /var/folders directory is returned
  • similar error is returned when, e.g. trying to commit using magit (c c from magit-status buffer)

Observed behaviour: 👀 💔
On a clean install of macOS Mojave, and using the develop branch of Spacemacs, functions that try to access the system $TMPDIR do not work.

For example, the emacs server doesn't start and trying to start it produces the backtrace given below. Another example is trying to do a git commit with magit, where it doesn't display a commit message buffer and instead returns this error: files--ensure-directory: Creating directory: Permission denied, /var/folders/9y

This does not happen when:

  • using the master branch of spacemacs (with no configuration changes)
  • running emacs with -q
  • running emacs from terminal (/Applications/Emacs.app/Contents/MacOS/Emacs -nw)

This is the relevant environment in terminal:

~ λ getconf DARWIN_USER_CACHE_DIR
/var/folders/mg/_y2tfty93cd0g7s368kggbw80000gn/C/
~ λ getconf DARWIN_USER_TEMP_DIR
/var/folders/mg/_y2tfty93cd0g7s368kggbw80000gn/T/
~ λ echo $TMPDIR
/var/folders/mg/_y2tfty93cd0g7s368kggbw80000gn/T/

And this in the GUI:

~ λ getconf DARWIN_USER_CACHE_DIR
/var/folders/mg/_y2tfty93cd0g7s368kggbw80000gn/C/
~ λ getconf DARWIN_USER_TEMP_DIR
/var/folders/mg/_y2tfty93cd0g7s368kggbw80000gn/T/
~ λ echo $TMPDIR 
/var/folders/9y/5gwns9bn6zbfg4yhd0g1pzjc0000gn/T/

The behavior is the same with Emacs 26.1 and an Emacs 27 compiled from source.

Expected behaviour: ❤️ 😄
Spacemacs uses the right temp directory

System Info 💻

  • OS: darwin
  • Emacs: 26.1
  • Spacemacs: 0.300.0
  • Spacemacs branch: develop (rev. 1c166c2)
  • Graphic display: t
  • Distribution: spacemacs
  • Editing style: hybrid
  • Completion: ivy
  • Layers:
(ivy auto-completion better-defaults emacs-lisp git markdown
     (shell :variables shell-default-height 30 shell-default-position 'bottom)
     (spell-checking :variables spell-checking-enable-by-default nil)
     (syntax-checking :variables syntax-checking-enable-tooltips nil syntax-checking-use-original-bitmaps t)
     version-control search-engine major-modes translation yaml graphviz restclient fasd theming themes-megapack shell-scripts windows-scripts spacemacs-navigation
     (org :variables org-want-todo-bindings 't)
     gnus ietf ansible vagrant xkcd ranger osx pdf latex pandoc
     (elfeed :variables rmh-elfeed-org-files
             (list "~/.spacemacs.d/elfeed.org"))
     (dash :variables helm-dash-docset-newpath "~/Library/Application Support/Dash/DocSets")
     nginx csv sx)
  • System configuration features: NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES THREADS

Backtrace 🐾

Debugger entered--Lisp error: (file-error "Creating directory" "Permission denied" "/var/folders/9y")
  signal(file-error ("Creating directory" "Permission denied" "/var/folders/9y"))
  files--ensure-directory("/var/folders/9y")
  make-directory("/var/folders/9y/5gwns9bn6zbfg4yhd0g1pzjc0000gn/T//emacs501" t)
  server-ensure-safe-dir("/var/folders/9y/5gwns9bn6zbfg4yhd0g1pzjc0000gn/T//emacs501")
  server-start(nil)
  funcall-interactively(server-start nil)
  call-interactively(server-start record nil)
  command-execute(server-start record)
  #f(compiled-function (cmd) #<bytecode 0x443de4ed>)("server-start")
  ivy-call()
  ivy-read("M-x " ("server-start" "debug-on-entry" "dotspacemacs/test-dotfile" "browse-url" "make-directory" "s" "cd" "5x5" "arp" "dbx" "dig" "erc" "ert" "eww" "ftp" "gdb" "irc" "jdb" "man" "mpc" "pdb" "pwd" "rsh" "sdb" "xdb" "calc" "deer" "diff" "dirs" "ffap" "gnus" "grep" "help" "ielm" "info" "life" "mail" "mpuz" "mwim" "ping" "pong" "smex" "talk" "term" "undo" "xkcd" 
tko commented

Some time ago spacemacs started caching environment variables in ~/.spacemacs.env file and I think it included TMPDIR. Since TMPDIR changes between restarts the cached value is going to be wrong and probably leads to errors such as these. Editing the file and removing TMPDIR (and other spurious variables) should help.

Yes, TMPDIR was in .spacemacs.env, removing it solved the problems. Thanks!

I've had the same issue today with the latest version of MacOSX and the solution above unfortunately didn't solve it for me. My GUI eshell output is as follows:

Welcome to the Emacs shell

~ λ echo $TMPDIR 
/var/folders/mm/5vzm564d6_q3z4016yqqpfs80000gn/T/
~ λ getconf DARWIN_USER_CACHE_DIR
/var/folders/c1/b0vz7dhs4rq__58c24nxzmt40000gn/C/
~ λ getconf DARWIN_USER_TEMP_DIR
/var/folders/c1/b0vz7dhs4rq__58c24nxzmt40000gn/T/

There is no /var/folders/mm directory on my machine

Edit: the solution for me was as per #11674 . Deleting the ~.spacemacs.env file entirely solved the issue for me.