ZIm/crates
Enrique Kessler Martínez 8c215d43ad
Fix pulling metadata out of broken symlinks (#22396)
## Problem

When developing extensions locally, developers will commonly put their
source code in a specific directory. Zed uses this directory to create a
symlink starting from `$HOME/Library/Application
Support/Zed/extensions/installed` (MacOS path). When a developer then
moves this source code and tries to reinstall the extension, Zed will
fail with an unhelpful message (you can check the #Testing section).

## Change Summary

With this PR, we fix this behaviour by handling broken symlinks
specifically when returning the metadata on `fs::metadata`. Today, we

1. Pull the symlink metadata.
2. Return it if the file was not a symlink OR if it is, pull the
metadata for the pointed file.

After this change gets merged, we return the Symlink metadata if the
symlink is broken. This makes the symlink be recreated since we remove
the symlink either way.

## Risks associated with this change

It's possible changing this behaviour will show additional cases where
we are handling broken symlinks incorrectly. I expect this to be a
better scenario AND backwards compatible. We have the same behaviour we
had for 1. existing symlinks 2. normal files.

## Testing

The way I have been reproducing this is by having a private extension of
my own. I install it using the `zed: install dev extension` command
after running `RUST_LOG=debug RUST_BACKTRACE=1 scripts/zed-local -1`.
Then I move the extension to a different directory.

Zed will now keeps a broken link on its `installed` directory:

```
❯ ll
Permissions Size User    Date Modified Name
lrwxr-xr-x@    - enrikes 24 Dec 12:15  brazil-config-zed-extension -> /Volumes/workplace/BrazilConfigZedExtension
drwxr-xr-x@    - enrikes  5 Dec 14:48  java
drwxr-xr-x@    - enrikes 12 Dec 13:04  kotlin
drwxr-xr-x@    - enrikes 25 Oct 08:13  rose-pine-theme
```

Before the patch, Zed shows on its logs:

```
2024-12-24T16:44:02+01:00 INFO  extension::extension_builder] compiled Rust extension /Users/enrikes/Documents/BrazilConfigZedExtension
[2024-12-24T16:44:02+01:00 INFO  extension::extension_builder] compiling grammar brazil_config for extension /Users/enrikes/Documents/BrazilConfigZedExtension
[2024-12-24T16:44:02+01:00 INFO  extension::extension_builder] checking out brazil_config parser
[2024-12-24T16:44:04+01:00 INFO  extension::extension_builder] compiling brazil_config parser
[2024-12-24T16:44:05+01:00 INFO  extension::extension_builder] compiled grammar brazil_config for extension /Users/enrikes/Documents/BrazilConfigZedExtension
[2024-12-24T16:44:05+01:00 INFO  extension::extension_builder] finished compiling extension /Users/enrikes/Documents/BrazilConfigZedExtension
[2024-12-24T16:44:05+01:00 ERROR extensions_ui] No such file or directory (os error 2)

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/backtrace.rs:331:13
   3: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /Users/enrikes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.94/src/backtrace.rs:27:14
   4: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:1989:27
   5: <fs::RealFs as fs::Fs>::metadata::{{closure}}
             at ./crates/fs/src/fs.rs:603:13
```

After the patch, the extension is installed and the symlink replaced for
a new one pointing to the user's directory choice.

```
2024-12-24T16:53:33.916022+01:00 [INFO] compiled Rust extension /Users/enrikes/Documents/BrazilConfigZedExtension
2024-12-24T16:53:33.916094+01:00 [INFO] compiling grammar brazil_config for extension /Users/enrikes/Documents/BrazilConfigZedExtension
2024-12-24T16:53:33.916225+01:00 [INFO] checking out brazil_config parser
2024-12-24T16:53:35.481602+01:00 [INFO] compiling brazil_config parser
2024-12-24T16:53:35.964189+01:00 [INFO] compiled grammar brazil_config for extension /Users/enrikes/Documents/BrazilConfigZedExtension
2024-12-24T16:53:35.964319+01:00 [INFO] finished compiling extension /Users/enrikes/Documents/BrazilConfigZedExtension
2024-12-24T16:53:36.213608+01:00 [INFO] rebuilt extension index in 39.108542ms
2024-12-24T16:53:36.213835+01:00 [INFO] extensions updated. loading 0, reloading 1, unloading 0
2024-12-24T16:53:36.375928+01:00 [INFO] rebuilt extension index in 34.478167ms
2024-12-24T16:53:36.376054+01:00 [INFO] extensions updated. loading 0, reloading 1, unloading 0
```

and

```
❯ ll
lrwxr-xr-x@    - enrikes 24 Dec 16:53  brazil-config-zed-extension -> /Users/enrikes/Documents/BrazilConfigZedExtension
drwxr-xr-x@    - enrikes  5 Dec 14:48  java
drwxr-xr-x@    - enrikes 12 Dec 13:04  kotlin
drwxr-xr-x@    - enrikes 25 Oct 08:13  rose-pine-theme
```


Release Notes:

- Fix broken symlinks when installing dev extensions

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
2025-01-21 17:09:16 +00:00
..
activity_indicator chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
anthropic Fix older Anthropic models not supporting -latest tags (#23372) 2025-01-20 13:19:15 -05:00
assets chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
assistant editor: Hide horizontal scrollbar if not visible (#23337) 2025-01-18 21:50:07 +00:00
assistant2 Wire up @mentioned files in assistant2 (#23389) 2025-01-20 21:33:18 -05:00
assistant_settings chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
assistant_slash_command Wire up @mentioned files in assistant2 (#23389) 2025-01-20 21:33:18 -05:00
assistant_slash_commands chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
assistant_tool chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
assistant_tools chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
audio chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
auto_update chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
auto_update_ui chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
breadcrumbs chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
call Allow filling co-authors in the git panel's commit input (#23329) 2025-01-18 22:57:17 +02:00
channel Allow filling co-authors in the git panel's commit input (#23329) 2025-01-18 22:57:17 +02:00
cli chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
client Require accepting ToS when enabling zeta (#23255) 2025-01-20 11:48:49 -03:00
clock chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
collab Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
collab_ui Allow filling co-authors in the git panel's commit input (#23329) 2025-01-18 22:57:17 +02:00
collections chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
command_palette Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
command_palette_hooks chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
context_server chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
context_server_settings chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
copilot chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
db chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
diagnostics chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
docs_preprocessor Prefer later bindings in keymap section for display in UI (#23378) 2025-01-20 23:20:15 +00:00
editor Fix completion labels becoming overly large due to LSP completion items with newlines (#23407) 2025-01-21 17:55:41 +02:00
evals chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extension chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extension_api chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extension_cli chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extension_host chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
extensions_ui chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
feature_flags chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
feedback chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
file_finder chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
file_icons chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
fireworks chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
fs Fix pulling metadata out of broken symlinks (#22396) 2025-01-21 17:09:16 +00:00
fsevent chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
fuzzy chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
git git: Skip directories in git status output (#23300) 2025-01-20 13:57:19 -05:00
git_hosting_providers chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
git_ui git_ui: Capitalize co-author prefix (#23365) 2025-01-20 16:00:47 +00:00
go_to_line chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
google_ai chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
gpui Prefer later bindings in keymap section for display in UI (#23378) 2025-01-20 23:20:15 +00:00
gpui_macros chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
html_to_markdown html_to_markdown: Restore ability to publish (#23293) 2025-01-17 17:57:13 +00:00
http_client chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
image_viewer chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
indexed_docs chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
inline_completion Require accepting ToS when enabling zeta (#23255) 2025-01-20 11:48:49 -03:00
inline_completion_button Toggle inline completion menu from keyboard (#23380) 2025-01-20 19:11:13 -03:00
install_cli chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
journal chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language Fix completion labels becoming overly large due to LSP completion items with newlines (#23407) 2025-01-21 17:55:41 +02:00
language_extension chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language_model chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language_model_selector chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language_models chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language_selector chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
language_tools Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
languages Fix completion labels becoming overly large due to LSP completion items with newlines (#23407) 2025-01-21 17:55:41 +02:00
livekit_client chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
livekit_client_macos chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
livekit_server chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
lmstudio chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
lsp Revert "lsp: Parse LSP messages on background thread - again (#23122)" (#23301) 2025-01-17 15:06:10 -07:00
markdown chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
markdown_preview Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
media chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
menu chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
multi_buffer chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
node_runtime chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
notifications chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
ollama chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
open_ai chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
outline chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
outline_panel chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
paths chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
picker chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
prettier chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
project Fix completion labels becoming overly large due to LSP completion items with newlines (#23407) 2025-01-21 17:55:41 +02:00
project_panel project_panel: Adjust entry background and border colors (#23403) 2025-01-21 11:13:46 -03:00
project_symbols chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
prompt_library chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
proto Allow filling co-authors in the git panel's commit input (#23329) 2025-01-18 22:57:17 +02:00
recent_projects terminal: Add scrollbar (#23256) 2025-01-18 17:36:41 +01:00
refineable chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
release_channel chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
remote chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
remote_server Fix project entry rename in Remote Development (#23382) 2025-01-21 12:48:40 +01:00
repl chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
reqwest_client chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
rich_text chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
rope chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
rpc chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
search chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
semantic_index chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
semantic_version chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
session chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
settings Display keymap errors on initial load (#23394) 2025-01-21 07:14:46 +00:00
settings_ui chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
snippet chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
snippet_provider chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
snippets_ui chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
sqlez chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
sqlez_macros chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
story chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
storybook Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
streaming_diff chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
sum_tree chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
supermaven chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
supermaven_api chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
tab_switcher tab_switcher: Preserve selected position on closed tabs (#22861) 2025-01-20 14:15:25 +02:00
task chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
tasks_ui chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
telemetry chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
telemetry_events chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
terminal terminal: Add scrollbar (#23256) 2025-01-18 17:36:41 +01:00
terminal_view terminal: Add scrollbar (#23256) 2025-01-18 17:36:41 +01:00
text chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
theme project_panel: Adjust entry background and border colors (#23403) 2025-01-21 11:13:46 -03:00
theme_extension chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
theme_importer chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
theme_selector chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
time_format chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
title_bar chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
toolchain_selector chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
ui Prefer later bindings in keymap section for display in UI (#23378) 2025-01-20 23:20:15 +00:00
ui_input chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
ui_macros chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
util Display keymap errors on initial load (#23394) 2025-01-21 07:14:46 +00:00
vcs_menu chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
vim Load all key bindings that parse and use markdown in error notifications (#23113) 2025-01-18 22:27:08 +00:00
vim_mode_setting chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
welcome chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
workspace workspace: Add actions for cycling between windows (#23356) 2025-01-20 11:34:18 +00:00
worktree windows: Fix FS-related issues (#23369) 2025-01-21 14:19:23 +08:00
zed Display keymap errors on initial load (#23394) 2025-01-21 07:14:46 +00:00
zed_actions chore: Use workspace fields for edition and publish (#23291) 2025-01-17 17:39:22 +01:00
zed_predict_tos Require accepting ToS when enabling zeta (#23255) 2025-01-20 11:48:49 -03:00
zeta Require accepting ToS when enabling zeta (#23255) 2025-01-20 11:48:49 -03:00