Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 125466 - readlink -f doesn't work on non-GNU userlands
Summary: readlink -f doesn't work on non-GNU userlands
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: eselect (show other bugs)
Hardware: All FreeBSD
: High normal
Assignee: Gentoo eselect Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2006-03-08 05:16 UTC by Diego Elio Pettenò (RETIRED)
Modified: 2006-04-14 10:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Elio Pettenò (RETIRED) gentoo-dev 2006-03-08 05:16:12 UTC
The new env eselect module make use of readlink -f but that option is not present in non-GNU readlinks.
The same thing can be achieved by a simple recursive function:

canonicalize() {
	link=$(readlink "$1")
	if [[ -n ${link} ]]; then
		canonicalize "$1"
	else
		echo "$1"
	fi
}

[although it needs a control to avoid infinite recursion if there's a circular linking]

An alternative can be the non-recursive function (seem less performant):

canonicalize() {
	currlink=$1
	currfile=$(readlink "$1")
	while [[ -n ${currfile} ]]; do
		currlink=${currfile}
		currfile=$(readlink "${currlink}")
	done
	echo ${currlink}
}

[also this requires a infinite break]

Without this, eselect 1.0.1 is not going to work on FreeBSD.
Comment 1 Ciaran McCreesh 2006-03-09 04:01:36 UTC
Does app-admin/realpath work on fbsd?
Comment 2 Diego Elio Pettenò (RETIRED) gentoo-dev 2006-03-09 04:23:27 UTC
As a charm.
Comment 3 Ciaran McCreesh 2006-03-09 04:34:01 UTC
Ok, how about we make this a configure thing, where we check for readlink -f then realpath then explode, then call the detected program via canonicalise (like we do for sed/gsed)? We could add a userland? dep on realpath...
Comment 4 Diego Elio Pettenò (RETIRED) gentoo-dev 2006-03-09 04:40:24 UTC
If you can do the check at runtime, which checks also for grealpath, I would suggest a || ( app-admin/realpath sys-apps/coreutils ) dependency...
Comment 5 Ciaran McCreesh 2006-03-09 04:52:49 UTC
I reaallllllllly don't want to do the check at runtime. Same with sed. Checking for greadlink at configure time is fine though.
Comment 6 Diego Elio Pettenò (RETIRED) gentoo-dev 2006-03-09 04:58:54 UTC
Okay, then let it fail gracefully if someone for instance builds with coreutils (so with greadlink) and then changes with realpath, it's not unlikely that things with || () deps require a rebuild when passing from one to the other...
Comment 7 Danny van Dyk (RETIRED) gentoo-dev 2006-03-30 12:54:32 UTC
Proposed fix is in SVN now.
Comment 8 Danny van Dyk (RETIRED) gentoo-dev 2006-04-14 10:42:40 UTC
Fixed as of eselect-1.0.2