haskell/cabal — pull request #1454 by Blaisorblade (2013-08-31 15:48:28+00:00)
Title: Topic/symlink owner heuristic (fix #1452)

After discussions with @dcoutts at Zurihac2013, I fixed #1452.

[I implemented the following logic](https://github.com/haskell/cabal/issues/1009#issuecomment-23607910) - we extract the template for bindir and expand occurrrences of $prefix, obtaining a template against which we match the target of the existing symlink. If it matches, we consider the symlink installed by cabal.

For instance, given a configuration like the following:

install-dirs user
prefix: /Users/pgiarrusso/Library/Haskell/$compiler/lib/$pkgid
-- bindir: $prefix/bin
we'd get /Users/pgiarrusso/Library/Haskell/$compiler/lib/$pkgid/bin as template.

Remaining issues:
- the matching uses ambiguous parsing, which is a potential performance problem since worst-case complexity might be exponential? But I currently don't believe it is a problem in practice.
- matching is still too liberal (fix soon) - we can't use the parsers for variables, since they are too greedy, so we just accept anything - but that right now includes even '/' (see `dotStar`).
- code might need cleanup to conform to coding standards