Skip to content

Ls symlink fix - #8276

Merged
fdncred merged 3 commits into
nushell:mainfrom
alesito85:ls-symlink-fix
Mar 20, 2023
Merged

fdncred merged 3 commits into
nushell:mainfrom
alesito85:ls-symlink-fix

Conversation

@alesito85

Copy link
Copy Markdown
Contributor

Description

Fixes #6706.

I took a look at this issue and it seems that the issue is because the path is canonicalized and thus derives to the target. I've tested it locally by checking if the path is a symlink and acting accordingly to not canonicalize it and it seems fine.

In current release if the target is deleted but the symlink remains and one ls's it, it throws a directory not found error. But with the fix it still shows the symlink (with red background, indicating missing target).

The change I've applied only triggers when ls is done on a symlink, on all other counts it should basically do the same as before.

User-Facing Changes

(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)

Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

List existing symlink and target

Current

ls a_symlink                                                                                                                                                                                ╭───┬────────┬──────┬──────┬──────────────╮
│ # │  name  │ type │ size │   modified   │
├───┼────────┼──────┼──────┼──────────────┤
│ 0 │ a_file │ file │  0 B │ 20 hours ago │
╰───┴────────┴──────┴──────┴──────────────╯

With fix

ls a_symlink                                                                                                                                                                                ╭───┬───────────┬─────────┬──────┬──────────────╮
│ # │   name    │  type   │ size │   modified   │
├───┼───────────┼─────────┼──────┼──────────────┤
│ 0 │ a_symlink │ symlink │  6 B │ 20 hours ago │
╰───┴───────────┴─────────┴──────┴──────────────╯

List existing symlink with missing target

Current

ls symfile_x                                                                                                                                                                          
Error: nu::shell::directory_not_found (link)

  × Directory not found
   ╭─[entry #13:1:1]
 1 │ ls symfile_x
   ·    ────┬────
   ·        ╰── directory not found
   ╰────

With fix

ls symfile_x                                                                                                                                                                          ╭───┬───────────┬─────────┬──────┬─────────────╮
│ # │   name    │  type   │ size │  modified   │
├───┼───────────┼─────────┼──────┼─────────────┤
│ 0 │ symfile_x │ symlink │  6 B │ 2 hours ago │
╰───┴───────────┴─────────┴──────┴─────────────╯

@codecov

codecov Bot commented Mar 1, 2023

Copy link
Copy Markdown

Codecov Report

Merging #8276 (d43dab3) into main (592e677) will decrease coverage by 0.01%.
The diff coverage is 99.48%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8276      +/-   ##
==========================================
- Coverage   67.72%   67.71%   -0.01%     
==========================================
  Files         621      620       -1     
  Lines       99312    99244      -68     
==========================================
- Hits        67258    67204      -54     
+ Misses      32054    32040      -14     
Impacted Files Coverage Δ
crates/nu-command/src/default_context.rs 99.78% <ø> (-0.01%) ⬇️
crates/nu-engine/src/glob_from.rs 74.13% <80.00%> (+0.55%) ⬆️
crates/nu-cli/src/print.rs 100.00% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/alias.rs 100.00% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/break_.rs 100.00% <100.00%> (ø)
...rates/nu-cmd-lang/src/core_commands/commandline.rs 54.68% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/continue_.rs 100.00% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/def.rs 100.00% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/def_env.rs 100.00% <100.00%> (ø)
crates/nu-cmd-lang/src/core_commands/do_.rs 95.27% <100.00%> (ø)
... and 175 more

@fdncred

fdncred commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

After your PR, is there a way to tell what the symlink is pointing to? Like I've seen some system says a_simlink -> a_file. I was thinking that's what our target column was for but maybe I'm wrong?

@alesito85

alesito85 commented Mar 1, 2023 •

Copy link
Copy Markdown
Contributor Author

This hasn't changed actually and is still displayed when used in conjunction with a switch ls -l {file}.

image
Note that in the first example the target still exists and in the second the target doesn't exist anymore.

@fdncred

fdncred commented Mar 1, 2023

Copy link
Copy Markdown
Contributor

Thanks for confirming @alesito85

@alesito85

Copy link
Copy Markdown
Contributor Author

No problem, let me know if you'd like me to check anything else.

@fdncred
fdncred merged commit 77e73ce into nushell:main Mar 20, 2023
@fdncred

fdncred commented Mar 20, 2023

Copy link
Copy Markdown
Contributor

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ls resolves a symlink which pointed to a file

2 participants