mxcl/homebrew — pull request #19480 by dmnd (2013-04-27 22:39:45+00:00)
Title: Overwrite existing symlinks with --overwrite

I had some problems and ended up reinstalling homebrew but some symlinks were left in my `/usr/local`, so I was getting this:

$ brew link --overwrite suite-sparse
Linking /usr/local/Cellar/suite-sparse/4.2.0... Warning: Could not link suite-sparse. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/suite-sparse/4.2.0/include/umfpack_solve.h
/usr/local/include/umfpack_solve.h may already exist.
/usr/local/include may not be writable.

`brew link` has `--overwrite` (you can see I tried it above), but that only works when the existing things are files. This small patch makes `--overwrite` work with existing symlinks, too, so you get a nicer error message:

$ brew link suite-sparse
Linking /usr/local/Cellar/suite-sparse/4.2.0... Warning: Could not link suite-sparse. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/suite-sparse/4.2.0/include/umfpack_solve.h
Target /usr/local/include/umfpack_solve.h already exists. You may need to delete it.
To force the link and delete this file, do:
brew link --overwrite formula_name

To list all files that would be deleted:
brew link --overwrite --dry-run formula_name

And now it works:

$ brew link --overwrite suite-sparse
Linking /usr/local/Cellar/suite-sparse/4.2.0... 87 symlinks created