Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Switch back to resolving symlinks forrbenv executable#1439

Merged
mislav merged 3 commits intomasterfromresolve-rbenv-symlink
Sep 29, 2022

Conversation

mislav
Copy link
Member

Considerations:

  • ./libexec/rbenv executable is the entrypoint to the program;

  • BASH_SOURCE might be the path to a symlink that has activated./libexec/rbenv;

  • We must resolve the symlink to learn where rbenv's libexec directory is;

  • It's not guaranteed that rbenv commands will always remain directly under their own "libexec" directory, since a package maintainer can change that, e.g. rbenv commands are sometimes placed into/usr/libexec/rbenv/*;

  • Resolving symlinks might fail and in that case we just assume rbenv project layout.

Fixes#1437 /cc@konsolebox

Reverts parts of#1428, therefore reintroducing ~4ms overhead at runtime to properly detect the location of rbenv scripts. I could not find a simpler way to do this; suggestions welcome!

Considerations:- `./libexec/rbenv` executable is the entrypoint to the program;- BASH_SOURCE might be the path to a symlink that has activated `./libexec/rbenv`;- We must resolve the symlink to learn where rbenv's libexec directory is;- It's not guaranteed that rbenv commands will always remain directly under their own "libexec" directory, since a package maintainer can change that, e.g. rbenv commands are sometimes placed into `/usr/libexec/rbenv/*`;- Resolving symlinks might fail and in that case we just assume rbenv project layout.
@konsolebox
Copy link

I could not find a simpler way to do this; suggestions welcome!

How about the solution I suggested wherebin/rbenv is changed to a calling script instead?

readlink=$(type -p greadlink readlink 2>/dev/null | head -n1)

Can be changed toreadlink=$(type -P readlink) || readlink=$(type -P greadlink) avoiding the use of
head and a pipe which likely summons another subshell.

resolved="$($readlink "$rbenv_bin" 2>/dev/null)"

$readlink here might be worth quoting.

libexec_dir andRBENV_ROOT might also be worth converting to their canonical paths since they are being compared.

@mislav
Copy link
MemberAuthor

Excellent suggestions; thank you!

How about the solution I suggested wherebin/rbenv is changed to a calling script instead?

That is also valid and I experimented with changing thebin/rbenv that ships with rbenv to be a script instead of a symlink tolibexec/rbenv. However, for backwards compatibility with other rbenv setups that may be using symlinks already, I thought it would be a nice touch thatlibexec/rbenv goes back to resolving symlinks, and if it has that ability, then I would rather keepbin/rbenv as a symlink.

konsolebox reacted with thumbs up emoji

@mislavmislav merged commited1a3a5 intomasterSep 29, 2022
@mislavmislav deleted the resolve-rbenv-symlink branchSeptember 29, 2022 13:27
@konsolebox
Copy link

Master version is working again thank you. Just a minor thing to consider: Ifgreadlink orreadlink exists as an exported function,type -p will print nothing but still return 0 exit status.type -P otoh will only return 0 if executable is found in path. Is there a reason whytype -p is preferred?

@mislav
Copy link
MemberAuthor

Ah, I didn't know that; thanks for explaining the distinction.

I have been usingtype -p for testing support for executables in all my bash scripts for years, and never have I encountered a bug report with that. I did not even know abouttype -P. I don't feel strongly enough about fixing this right now, so let's see if we can get away with this. If someone exports a function calledreadlink from bash, I hope that they make that function behave like readlink.

@mislav
Copy link
MemberAuthor

Ah, only now I understand what you were saying: if someone did export a function calledgreadlink, the result will be an empty string. I will quickly fix this; thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

rbenv scripts no longer allowed in another directory besides <bin_dir>/../libexec
2 participants
@mislav@konsolebox

[8]ページ先頭

©2009-2025 Movatter.jp