nushell / nushell/nushell

`rm -r link/` deletes symlink's target instead of symlink itself due to trailing slash

Open
#12,453 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A:file-system status:needs-triage
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

Describe the bug

See title

How to reproduce
mkdir src
ln -s src/ link

ls -l . | select name type target
╭───┬──────┬─────────┬────────╮
│ # │ name │  type   │ target │
├───┼──────┼─────────┼────────┤
│ 0 │ link │ symlink │ src/   │
│ 1 │ src  │ dir     │        │
╰───┴──────┴─────────┴────────╯

rm -r link/

ls -l . | select name type target
╭───┬──────┬─────────┬────────╮
│ # │ name │  type   │ target │
├───┼──────┼─────────┼────────┤
│ 0 │ link │ symlink │ src/   │ # dangling symlink
╰───┴──────┴─────────┴────────╯

echo "Oh no I just deleted my real dir!"
Expected behavior

rm should return an error like the system rm:

^rm -r link/
rm: cannot remove 'link/': Not a directory
Screenshots

No response

Configuration
key value
version 0.92.1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.76.0 (07dca489a 2024-02-04) (built from a source tarball)
cargo_version cargo 1.76.0
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which
installed_plugins query
Additional context

rm -r link without a trailing slash works as expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the rm command entry point and reproduce the linked-directory case with rm -r link/, comparing it with rm -r link and system rm behavior. Done means a trailing slash on a symlink returns a not-directory error without deleting the target, while the existing no-slash behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.