Skip to content

Conversation

@cspotcode
Copy link

@cspotcode cspotcode commented Sep 6, 2019

I have only informally tested this locally, so I can't prove it works, and I haven't had time to write tests.

Idea is pretty simple: use [[ -L to check if final path is to a symlink. Use readlink to read it, concatenate the path back together, and try the entire thing all over again using the newly computed path.

#2

@cspotcode
Copy link
Author

I added a test, and it looks like it's working.

@morgant
Copy link
Owner

morgant commented Sep 14, 2019

Thanks for submitting this fix, I'm in the process of testing it.

@cspotcode
Copy link
Author

I just realized your README says you explicitly avoid using readlink and this PR uses readlink. However, I think it's ok because we're not using any special flags so it seems compatible with the readlink bundled in MacOS.

@morgant
Copy link
Owner

morgant commented Sep 15, 2019

I had completely forgotten about not wanting a readlink prerequisite. It certainly appears to be available under macOS 10.14 Mojave, but must not have been included in prior versions. I'll look into that, as well.

@morgant
Copy link
Owner

morgant commented Sep 15, 2019

I believe that pwd -P might allow us to work around the readlink requirement.

@cspotcode
Copy link
Author

cspotcode commented Sep 15, 2019 via email

@morgant
Copy link
Owner

morgant commented Sep 28, 2019

@cspotcode Good point, pwd -P won't work when the file itself is a symlink. I've added tests for files being symlinks (which is broken) and paths including symlinks (which work).

I think that readlink is available on most platforms, but some of the options (-e?) which are often used to implement the whole of realpath are not. That said, I think we should be able to use readlink to resolve a symlink. I'll review your code again.

@morgant
Copy link
Owner

morgant commented Sep 28, 2019

Honestly, I'm not fully a fan of the while/continue, but it works and is pretty minimal. It passes the new tests, which is good.

If you want to merge the updated tests into your branch I'll merge this. Huge thanks for catching this glaring bug and fixing it!

@cspotcode
Copy link
Author

cspotcode commented Sep 28, 2019 via email

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.

2 participants