Fix symlink management in extension packaging backend.

Review Request #14902 — Created March 14, 2026 and updated

Information

Djblets
release-5.x

Reviewers

Our extension packaging backend creates a symlink for .npm-workspaces,
but the implementation managing it had a bug in cases where we're
potentially doing things multiple times.

In our case, the Power Pack gets built repeatedly for different Python
versions. After the first build, we clean up the tree, leaving the
workspaces link dangling. In this case, the call to .exists() returns
False, but the symlink is still there, and we'll fail when attempting
to create it again.

The fix is to check first if it's a symlink and unlink, and then
otherwise check if there's something present which is not a symlink.

Did a test build of an extension.

Summary ID
Fix symlink management in extension packaging backend.
Our extension packaging backend creates a symlink for `.npm-workspaces`, but the implementation managing it had a bug in cases where we're potentially doing things multiple times. In our case, the Power Pack gets built repeatedly for different Python versions. After the first build, we clean up the tree, leaving the workspaces link dangling. In this case, the call to `.exists()` returns `False`, but the symlink is still there, and we'll fail when attempting to create it again. The fix is to check first if it's a symlink and unlink, and then otherwise check if there's something present which is not a symlink. Testing Done: Did a test build of an extension.
wyqswrllxmwllopmzykwsksmlxnvrkyv
Checks run (2 succeeded)
flake8 passed.
JSHint passed.