Skip to content

Fix path relative-to for case-insensitive filesystems#16310

Merged
WindSoilder merged 5 commits intonushell:mainfrom
hustcer:feature/path-relativeTo
Aug 4, 2025
Merged

Fix path relative-to for case-insensitive filesystems#16310
WindSoilder merged 5 commits intonushell:mainfrom
hustcer:feature/path-relativeTo

Conversation

@hustcer
Copy link
Copy Markdown
Contributor

@hustcer hustcer commented Jul 31, 2025

fixes #16205

Description

  1. Adds fallback: On case-insensitive filesystems (Windows, macOS), falls back to case-insensitive comparison when the standard comparison fails
  2. Maintains filesystem semantics: Only uses case-insensitive comparison on platforms where it's appropriate

Before:

$> "/etc" | path relative-to "/Etc"
Error: nu::shell::cant_convert

  × Can't convert to prefix not found.
   ╭─[entry #33:1:1]
 1 │ "/etc" | path relative-to "/Etc"
   · ───┬──
   ·    ╰── can't convert string to prefix not found
   ╰────

After:

For Windows and macOS:

$> "/etc" | path relative-to "/Etc" | debug -v
""

Release notes summary

path relative-to works better for case-insentitive filesystems, this works on Windowes or macOS: "/etc" | path relative-to "/Etc"

Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix! Just left some ideas on try_case_insensitive_strip_prefix

@hustcer hustcer added notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes notes:fixes Include the release notes summary in the "Bug fixes" section labels Aug 3, 2025
@sholderbach
Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!
I found out MS handles something like C:\ and relative path(like ../) at the same time, I don't think we need such complexity for now

@WindSoilder WindSoilder merged commit 9f4c3a1 into nushell:main Aug 4, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.107.0 milestone Aug 4, 2025
@hustcer hustcer deleted the feature/path-relativeTo branch August 4, 2025 14:51
}

/// Check if the current filesystem is typically case-insensitive
fn is_case_insensitive_filesystem() -> bool {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if hardcoding this based on the platform is a good idea. You can access NTFS or APFS from Linux, isn't there a better way to check the path belonging to a case insensitive fs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to make this configurable in some way. On Windows at least, case-sensitivity can be set per-directory. But I would not expect relative-to to need to stat each directory in the path (e.g. a path may not (yet) exist or it might be inaccessible).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider this issue earlier, but opted for this approach as it's the simplest and has minimal performance impact. If you have better ideas, feel free to refine it further

@Bahex Bahex added notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. and removed notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes labels Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Include the release notes summary in the "Bug fixes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

path relative-to does not work as expected with case-insensitive paths on case-insensitive filesystems

6 participants