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

cd: <symlink target file>: Not a directory #1118

Closed
HQJaTu opened this issue Mar 14, 2018 · 8 comments
Closed

cd: <symlink target file>: Not a directory #1118

HQJaTu opened this issue Mar 14, 2018 · 8 comments

Comments

@HQJaTu
Copy link

HQJaTu commented Mar 14, 2018

File pyenv assumes, that it can follow symlinks in abs_dirname():

  abs_dirname() {
    local path="$1"

    # Use a subshell to avoid changing the current path
    (
    while [ -n "$path" ]; do
      cd "${path%/*}"
      local name="${path##*/}"
      path="$(resolve_link "$name" || true)"
    done

    pwd
    )
  }

However, the target file can be a symlink, and it cannot be followed.

Example from Ansible. Listing of ansible/bin/:

    ansible
    ansible-playbook -> ansible

Executing ~/ansible/bin/ansible-playbook will work, but during it a ~/.pyenv/libexec/pyenv: line 44: cd: ansible: Not a directory is emitted.

A suggested fix would be:

      path="$(test -d "$name" && resolve_link "$name" || true)"

... to test if the destination is a directory that can be cdd into.
If yes, follow that. If not, stop iterating without emitting errors.

@webknjaz
Copy link

Haha 🤣
I've just spotted this yesterday, did debugging today and also with ansible-test script and going to prepare somewhat similar patch :)

webknjaz added a commit to webknjaz/pyenv that referenced this issue Mar 15, 2018
This corrects the deffect where pyenv tries to determine an absolute
path of the directory containing a file and follows symlinks
manually. Because of missing check it behaved correctly, but a
misleading error message was shown in the terminal output.

Thanks to @HQJaTu for the patch
@webknjaz
Copy link

Looks like there's a test for it and it's broken https://travis-ci.org/pyenv/pyenv/jobs/353851590#L523-L529

@webknjaz
Copy link

ref: #379, #404

@webknjaz
Copy link

Okay.. test is not broken, but the fix is imperfect

@webknjaz
Copy link

Got a solution: resolve pwd with --follow when returning

@webknjaz
Copy link

Pipeline succeeds, dunno how to catch this with a test though.

@webknjaz
Copy link

Ping @joshfriend @yyuu 🔔
I've fixed it, please review the PR #1120.

@blueyed
Copy link
Contributor

blueyed commented Sep 19, 2018

Closing as duplicate of #580.

@blueyed blueyed closed this as completed Sep 19, 2018
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

No branches or pull requests

3 participants