silentbicycle / lookup

Search for a file in parent directories, up to / .

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Symlinks

nyarly opened this issue · comments

Here's fun: realpath (on Linux, at least) resolves symlinks as it flattens ..'s - so if the file you're trying to lookup turns out to be a symlink, you actually get the resolved file.

Is that a problem? It seems like symlink lookup is reasonable here, though I suppose I could run realpath on just the directory and then add the file.

The ways I've tended to use lookup, it wouldn't make a difference, but has it caused problems? Or just been surprising?

Sorry for the long delay in reply -

I've been using lookup (quite successfully! Thanks!) to find a rule file for dispatching edit commands to the right Vim. So: cd to dirname of file, lookup rulefile, apply rules.

Because these rule files are mostly stereotypical, I have a ~/rules directory where I keep the masters, and symlink them into place.

So the right rules get applied - but the problem is that the application depends on where the rules file is found - there's one "test" Vim per workspace, for instance. Finding the "root" rulefile means that they're all test:~rules.

Time being, I've been dirname $(lookup -r $rules) and them realpath -s -m --relative-base=$root_path $path

Looking at man 3 realpath it looks like doing something different would close to double the size of lookup, though, since I don't see a syscall to produce the absolute path but not resolve symlinks.

So, my weird usecase. It has a workaround. Not a FAQ item I'd want to have to add, but easier than the alternative.

Ohhhhhh, I think I follow. I'm not sure what the best way to handle that is implementation-wise, but a -s (don't follow symlinks) option would make a lot of sense.