microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
161.92k stars 28.46k forks source link

Incorrect symlink on `code` command under macOS App Translocation #209356

Open prophile opened 4 months ago

prophile commented 4 months ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Install VS code into /Applications in a manner which triggers App Translocation, such as installing from Homebrew.
  2. Shell Command: Install code(or code-insiders) command into PATH
  3. Reboot
  4. Run code (or code-insiders) from the command line
% code-insiders .
zsh: command not found: code-insiders

The workaround to fix this locally is to (I realise this is stupid, but it causes App Translocation not to run on the current OS version) drag the application in Finder.app from /Applications somewhere else, such as the desktop, then drag it back, then rerun "Install code command into PATH".

App Translocation is a macOS security feature which under a frustratingly nondeterministic set of circumstances causes the application to be copied into a temporary directory and then run from there. In this case the downstream effect is that /usr/local/bin/code is installed as a symlink not to /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code but rather to /private/var/folders/<randomly generated nonsense>/AppTranslocation/<more nonsense>/Visual Studio Code.app/Resources/app/bin/code.

The temporary directory for the translocated app is temporary, so once the app exits or the system reboots, the path no longer exists, leaving /usr/local/bin/code as a broken symlink.

The workaround I've used right now is to manually move the app around in a way to not cause App Translocation to fire, but this is brittle.

prophile commented 4 months ago

I realise the symlink is needed to find the bundle; so in case an alternative is of any use so you could copy into /usr/local/bin/code rather than symlinking:

% osascript -e 'POSIX path of (path to application id "com.microsoft.VSCodeInsiders")'
/Applications/Visual Studio Code - Insiders.app/
prophile commented 4 months ago

Alternatively, /private will reliably be at the start of the path if App Translocation is in effect, so you could raise an error or warning when the user tries to run "Install code command into PATH" which would at least make the situation clearer.

SpecialThing44 commented 3 months ago

I think I triggered this issue by double clicking on the Application in the disk image (And eventually ejecting the disk image)

tamulis commented 1 month ago

Looks like to be fixed, at least installing the Homebrew way.