On my machine, there is a file:
/var/lib/flatpak/exports/bin/com.github.tchx84.Flatseal
Which is a symlink whose content is:
../../app/com.github.tchx84.Flatseal/current/active/export/bin/com.github.tchx84.Flatseal
That is, a relative symlink pointing to the path:
/var/lib/flatpak/app/com.github.tchx84.Flatseal/current/active/export/bin/com.github.tchx84.Flatseal
That path itself contains some symlinks - current is a symlink to x86_64/stable/, and inside that, active is a symlink to 79456afc5a115a457bd99c85e428d47637ec978293aafb328ccc450c13bfeb80/. The absolute path is:
/var/lib/flatpak/app/com.github.tchx84.Flatseal/x86_64/stable/79456afc5a115a457bd99c85e428d47637ec978293aafb328ccc450c13bfeb80/export/bin/com.github.tchx84.Flatseal
I would like to make a copy of that original symlink somewhere else (say /home/foo/bin).
I can't just copy it with cp -d (aka cp --no-dereference --preserve=links), because that simply copies the content of the symlink, and that's a relative path, so when copied to a different directory, it results in a broken link. As far as i can tell, there is no way to 'copy' a relative symlink in a way which actually changes it to preserve the resulting target.
I can create a new symlink, but to do that, i need to know the absolute path pointed to by the original. How can i determine that?
A simple readlink just reads the relative path. A readlink -f (aka readlink --canonicalize) or realpath fully canonicalises the link - it works out the absolute path, then goes through it and resolves all the other symlinks it finds. That results in a path with all the hexadecimal gibberish in it, which is not what i want (it will break as soon as i update that flatpak!).
So how i can just read and resolve the actual symlink? Alternatively, is there a way to resolve a relative path against an absolute one?