fix(ln): surface remove failure under -f instead of falling through to symlink#1583
Merged
Conversation
…o symlink Previously, ln -f swallowed the result of ctx.fs.remove(...) and called ctx.fs.symlink unconditionally. If the destination is a non-empty directory, the non-recursive remove fails, but the symlink insert on the in-memory VFS overwrites the directory entry while leaving its children orphaned in the entries map — a corruption of FS state. Propagate the remove error and return exit 1 with a real-shell-style "ln: cannot remove '<name>': <reason>" message. Add a unit-level regression test (test_ln_force_over_non_empty_dir_fails) and a spec case (ln_force_dir_dest_fails) that ensures the child file is still present after the failed ln -sf. Closes #1577
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 9ae154e | Commit Preview URL Branch Preview URL |
May 07 2026, 04:05 AM |
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.
Closes #1577.
Summary
ln -fpreviously swallowed the result ofctx.fs.remove(...)and calledctx.fs.symlink(...)unconditionally. When the destination is a non-empty directory,remove(..., false)fails, but the symlink insert on the in-memory VFS overwrites the directory entry while leaving its children orphaned in theentriesmap — a corruption of filesystem state.Fix
removeerror and return exit 1 with a real-shell-styleln: cannot remove '<name>': <reason>message.test_ln_force_over_non_empty_dir_fails(verifies non-zero exit + child file still present).ln_force_dir_dest_failscovering the same scenario from the user-facing CLI.Notes
The issue also suggests "make VFS
symlinkreject existing paths defensively". That change has broader implications for other callers (overlay, mountable, cp -R) and warrants its own PR — punting for now.Test plan
cargo test -p bashkit --lib builtins::fileops::tests::test_ln_force_over_non_empty_dir_failscargo test -p bashkit --test spec_tests bash_spec(passes; new ln_force_dir_dest_fails case included)cargo fmt --all -- --checkcargo clippy --all-features --all-targets -- -D warningsGenerated by Claude Code