Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realpath -s doesn't resolve to absolute path #7574

Closed
kidonng opened this issue Dec 24, 2020 · 4 comments
Closed

realpath -s doesn't resolve to absolute path #7574

kidonng opened this issue Dec 24, 2020 · 4 comments
Labels
bug Something that's not working as intended enhancement
Milestone

Comments

@kidonng
Copy link
Contributor

kidonng commented Dec 24, 2020

❯ fish --version
fish, version 3.1.2-1798-g4dae10691

❯ echo $version
3.1.2-1798-g4dae10691

Glad to see a -s (--no-symlinks) option is added to realpath in 568f903. But there are currently two issues with realpath:

  • share/functions/realpath.fish isn't updated along with the builtin, so one can't just use realpath -s, they have to type builtin realpath -s instead.
  • While the above is a minor issue, the main problem this issue is about is realpath -s doesn't resolve to absolute path at all.
❯ pwd
/Users/kid

❯ ls -l .cache
lrwxr-xr-x  1 kid  staff  14 Dec  5 11:29 .cache -> Library/Caches

❯ builtin realpath -s ~/.cache
/Users/kid/.cache

❯ builtin realpath -s .cache
.cache

But I expect .cache to be resolved to the absolute path /Users/kid/.cache.

I noticed the -s flag calls normalize_path internally, but the function seems to only deal with . and .., and it doesn't resolve to a absolute path. So is realpath -s's behavior intended? Or is this just a implementation flaw?

@kidonng kidonng changed the title realpath -s doesn't resolve absolute path realpath -s doesn't resolve to absolute path Dec 24, 2020
@krobelus krobelus modified the milestones: fish-future, fish 3.2.0 Dec 24, 2020
@krobelus
Copy link
Member

Good catch, this is used in fish_add_path.

share/functions/realpath.fish isn't updated along with the builtin

Probably it's just meant as fallback for now.

@krobelus krobelus added the bug Something that's not working as intended label Dec 24, 2020
@zanchey
Copy link
Member

zanchey commented Dec 24, 2020

share/functions/realpath.fish isn't updated along with the builtin

It looks there to me:
https://github.com/fish-shell/fish-shell/blob/master/share/functions/realpath.fish#L25

@kidonng
Copy link
Contributor Author

kidonng commented Dec 26, 2020

Probably it's just meant as fallback for now.

@krobelus Thanks for the fix! But what do you mean by fallback? I think Fish already uses external realpath if available.

The outdated realpath function gives really confusing message:

❯ realpath -s .
realpath: These flags are not allowed by fish realpath: 's -s strip -s'

realpath - convert a path to an absolute path without symlinks

realpath PATH

DESCRIPTION
realpath resolves a path to its absolute path.

fish provides a realpath builtin as a fallback for systems where
there is no realpath command, your OS might provide a version with
more features.

If a realpath command exists, it will be preferred, so if you want to
use the builtin you should use builtin realpath explicitly.

The following options are available:

· -s or --no-symlinks: Don't resolve symlinks, only make paths abso‐
lute, squash multiple slashes and remove trailing slashes.

Notice how the bold text conflicts with each other.

@zanchey See https://github.com/fish-shell/fish-shell/blob/master/share/functions/realpath.fish#L36, it will refuse any options.

@krobelus
Copy link
Member

Thanks for the explanation, d6dd532 should fix that.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended enhancement
Projects
None yet
Development

No branches or pull requests

3 participants