Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home directory on alternate volume causes "Failed to write settings to file" #23907

Open
notpeter opened this issue Jan 30, 2025 · 3 comments
Open
Labels
reproducible Verified steps to reproduce included

Comments

@notpeter
Copy link
Member

Summary

User home directories on volumes other than / prevent Zed from performing actions which modify ~/.config/zed/settings.json.

Steps to trigger the problem:

  1. Create a new APFS volume or attach an external drive.
  2. Create a new user whose home directory on a drive other than /
  3. Open Zed, do some action which attempts to re-write settings (select model from Assistant, change default keymap, etc).

Actual Behavior:

2024-09-12T08:19:33.679273+10:00 [ERROR] Failed to write settings to file "/Users/ext/xxx/.config/zed/settings.json"

Caused by:
0: failed to persist temporary file: Cross-device link (os error 18)
1: Cross-device link (os error 18)

Expected Behavior:
Settings file is saved.

Workaround:
Create a symlink at `~/

Editors note (@notpeter): I have not performed these steps and derived them from comments here:

Zed Version and System Specs

Zed: v0.150.0 (Zed Preview)
OS: macOS 15.0.0
Memory: 16 GiB
Architecture: x86_64

@notpeter notpeter added the reproducible Verified steps to reproduce included label Jan 30, 2025
@kopparam
Copy link

Yep this is my setup and I can reproduce this error and workaround.

@kopparam
Copy link

kopparam commented Feb 3, 2025

@notpeter my thoughts on this if it helps.

Searching for the error reveals that it is from Rust and happens when it tries to write to a file which hard links to the source file on another file system. Is the setting.json stored in /tmp or something?

@notpeter
Copy link
Member Author

notpeter commented Feb 3, 2025

Doesn't require hard links, just moving/renaming across file system boundaries.

I haven't looked at this code specifically, but likely Zed is likely writing the new content to a file and then renaming it into place. The thinking is that this makes the update more-atomic and there is little chance of a half-written settings file on disk.

I think we should be potentially able to stat the ~/.config/zed/settings.json (or the target file if it is a symlink) and the temporary dir to compare if they are on on the same filesystem and if so, use the existing code, and if not write the file in an alternate way.

stat -f=%d "$(readlink -f ~/.config/zed/settings.json)"
stat -f=%d /tmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reproducible Verified steps to reproduce included
Projects
None yet
Development

No branches or pull requests

2 participants