fix: handle EXDEV cross-device errors in atomic_replace - #33508
Closed
OmarB97 wants to merge 3 commits into
Closed
Conversation
When config files (e.g. ~/.hermes/config.yaml) are symlinked to a different filesystem — common on WSL where dotfiles live under /mnt/c/ — os.replace() fails with EXDEV (errno 18: Invalid cross-device link). Fall back to shutil.copy2 + os.unlink when EXDEV is raised. copy2 preserves metadata (permissions, timestamps) so the result is equivalent. Non-EXDEV errors (EACCES, etc.) still propagate. This affects all atomic write paths (atomic_yaml_write, atomic_json_write, atomic_roundtrip_yaml_update) since they all route through atomic_replace. Added 4 regression tests: - Direct EXDEV fallback on plain file - EXDEV fallback preserving symlinks - Non-EXDEV errors are not swallowed - End-to-end atomic_yaml_write EXDEV recovery
…cross-device-exdev # Conflicts: # tests/test_atomic_replace_symlinks.py # utils.py
OmarB97
force-pushed
the
fix/atomic-replace-cross-device-exdev
branch
from
June 16, 2026 01:46
439f60a to
ad7b67e
Compare
Contributor
|
Thanks for the EXDEV investigation and regression coverage. Automated hermes-sweeper review found this is already implemented on current
The linked #34252/#34262 discussion concerns the same root cause. Closing as superseded by current main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When config files (e.g.
~/.hermes/config.yaml) are symlinked to a different filesystem — common on WSL where dotfiles live under/mnt/c/—os.replace()fails withEXDEV(errno 18: Invalid cross-device link).This causes every
hermes config setcommand to crash with:Fix
Catch
EXDEVinatomic_replaceand fall back toshutil.copy2+os.unlink.copy2preserves metadata (permissions, timestamps) so the result is equivalent. Non-EXDEV errors (EACCES, etc.) still propagate normally.This affects all atomic write paths (
atomic_yaml_write,atomic_json_write,atomic_roundtrip_yaml_update) since they all route throughatomic_replace.Test Plan
atomic_yaml_writeEXDEV recoveryContext
WSL users who symlink their dotfiles repo to
~/.hermes/config.yamlhitting a Windows mount path under/mnt/c/. The temp file is created in the WSL filesystem (~/.hermes/), butos.replace's underlyingrename()syscall can't cross filesystem boundaries.Fixes #34252 — credit to @ccwssy for the root-cause analysis of the cross-device rename failure.