Skip to content

Preserve user-managed /usr/local/bin/code in RPM %post scriptlet#310054

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/rpm-postscript-preserve-user-code-link-236132
Open

Preserve user-managed /usr/local/bin/code in RPM %post scriptlet#310054
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/rpm-postscript-preserve-user-code-link-236132

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What this PR does

The RPM %post scriptlet currently removes /usr/local/bin/code unconditionally on every install/upgrade of the stable code package:

%post
# Remove the legacy bin command if this is the stable build
if [ "%{name}" = "code" ]; then
    rm -f /usr/local/bin/code
fi

/usr/local/bin/code is not a path owned by this package, and it's a common place for users to drop a wrapper script (for example, to launch /usr/bin/code with extra flags like --ozone-platform=wayland system-wide). Deleting it on every RPM upgrade silently destroys user-managed files.

This PR keeps the legacy cleanup, but only when the file is a symlink pointing at the target the package itself used to install (/usr/share/code/bin/code / %{_datadir}/%{name}/bin/%{name}). Regular files (user wrapper scripts) and symlinks to other targets are left untouched.

Behavior change

  • Before: rm -f /usr/local/bin/code ran on every %post, removing whatever was at that path.
  • After: removal happens only when /usr/local/bin/code is a symlink whose target is the legacy package-installed location.

This preserves the original intent (cleaning up the legacy symlink from very old packages) without trampling files the user owns.

Testing notes

This affects RPM packaging only and is exercised at install time. Manual verification scenarios:

  1. A regular file at /usr/local/bin/code (e.g. a wrapper shell script) -> preserved across RPM upgrade.
  2. A symlink at /usr/local/bin/code -> /some/user/path/code -> preserved across RPM upgrade.
  3. A symlink at /usr/local/bin/code -> /usr/share/code/bin/code (legacy package layout) -> removed, matching previous cleanup behavior.
  4. No file at /usr/local/bin/code -> no-op.

Fixes #236132

The RPM %post scriptlet unconditionally removed /usr/local/bin/code,
which deleted user-installed wrapper scripts or symlinks that happened
to live at that path. The path is not owned by the package and is a
common location for users to drop wrapper scripts (for example to add
flags like --ozone-platform=wayland system-wide).

Only remove /usr/local/bin/code when it is a symlink pointing at the
location previously installed by this package, so that user-managed
files at that path are preserved.

Fixes microsoft#236132
@yogeshwaran-c yogeshwaran-c force-pushed the fix/rpm-postscript-preserve-user-code-link-236132 branch from 50d7aeb to f9aa01d Compare April 15, 2026 02:27
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Apr 15, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@rzhao271

Matched files:

  • resources/linux/rpm/code.spec.template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPM %post scriplet deletes /usr/local/bin/code

2 participants