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

[suggestion] emulate readlink using posix ls #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

smoon8
Copy link

@smoon8 smoon8 commented May 11, 2016

stat(1) is not posix compatible.

emulated readlink using ls

@@ -109,3 +109,7 @@ _gnu_stat_readlink() {
_bsd_stat_readlink() {
stat -f %Y -- "$1" 2>/dev/null
}

_posix_ls_readlink() {
LC_TIME=POSIX ls -l -- "$1" | sed -e 's/^.\{11\}\ *[0-9]\{1,\}\ *[a-zA-Z\._@\$-]\{1,\}\ *[a-zA-Z\._@\$-]\{1,\}\ *[0-9]\{1,\}\ *[^ ]*\ *[0-9]\{1,2\}\ *[^\ ]*\ \(.*\)/\1/g' -e 's/.* -> //g' 2>/dev/null
Copy link
Owner

Choose a reason for hiding this comment

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

Wow, it'll take me a little bit to wrap my head around that regex.

Does the g flag do anything when the substitution match is anchored to the beginning of the line with ^?

Copy link
Author

Choose a reason for hiding this comment

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

the g flag does nothing. it's just my habbit when i write regex.

@mkropat
Copy link
Owner

mkropat commented May 12, 2016

Thanks for the PR! I think you're right, ls is probably a more reliable way to emulate readlink support.

Do you see any reason to keep around the stat readlink emulation? I'm inclined to get rid of it if there's ls readlink emulation.

Also, it might be nice to have an automated test or two around this change, but I'm not super worried about it since it's a bonus feature that's basically a big regex.

I can test this out and verify that it seems to work right sometime in the next few days. Or if someone else wants to try it out and vouch for the change, I'd consider merging it sooner.

@smoon8
Copy link
Author

smoon8 commented May 13, 2016

the ls readlink emulation is just suggestion. so i didnt consider removing the stat readlink emulation.
i think the ls readlink emulation can cover the stat readlink emulation.

and i was careless about an automated test. it's my fault. i'll add automated test soon.

i didnt usually pay attention about automated test. if i may, can i ask you an advice while i add an automated test?

smoon added 2 commits May 13, 2016 14:02
ls(1) stderr redirect to /dev/null
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