Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstalling brew-cask-installed mosh removes hundreds of symlinks in /usr/ #2650

Closed
wallacewinfrey opened this issue Jan 27, 2014 · 8 comments · Fixed by #2670
Closed

Uninstalling brew-cask-installed mosh removes hundreds of symlinks in /usr/ #2650

wallacewinfrey opened this issue Jan 27, 2014 · 8 comments · Fixed by #2670

Comments

@wallacewinfrey
Copy link

Today I had an alarming experience installing mosh ( bfcb76a )

I ran:

brew cask install mosh

then decided to uninstall it and ran:

brew cask uninstall mosh

After running the uninstaller, the output of which appeared normal, I noticed that /usr/bin/tar was missing. A quick check into /var/log/system.log revealed that the uninstaller process had actually removed hundreds of symlinks from /usr/

Here's a gist of the output demonstrating the installation/uninstallation and relevant entries from /var/log/syslog. It is preceded by my zsh history file entries showing the commands as executed.

I suppose it's possible that some other process decided to intervene at this exact point and time, and I've not had the time to reconstruct the actual sequence of events leading to this issue (too busy trying to rebuild my filesystem) but given the timestamps, the unknown TTY in the sudo output, and the fact that the brew-cask version of Mosh inexplicably requires the use of sudo (the homebrew install of mosh has no such requirement), I'm inclined to believe that it was an unfortunate combination of brew-cask, the Mosh formula, and my own ignorance for believing that the use of sudo was necessary.

@rolandwalker
Copy link
Contributor

Hi! I'm incredibly sorry this happened to you, but glad that you turned it into a very useful report!

I had the same problem when uninstalling send-to-kindle.rb. I lost /usr/bin/tar as well as other development links.

That was the impetus behind a series of failsafes added in PRs #2595, #2623, #2613. And @vmrob has now joined in this effort with #2624. Only one of those PRs is merged so far. If you can help with reviewing the pending ones, please do so.

Those patches are essential for making sure rm can't make any mistakes. After #2624, I intend to add failsafes on the inputs given to rm. I was going to start with the bill-of-materials in the send-to-kindle pkg file. You have given me another pkg file to work with, which is mosh -- great.

Anyone else who has a similar problem on uninstall -- please post the relevant package name in this issue!

Also, I didn't really want to wreak havoc on my machine twice, so I never duplicated the uninstall bug. If anyone has OS X virtualized, you could help us with this important issue.

@ghost ghost assigned rolandwalker Jan 27, 2014
@vmrob
Copy link
Contributor

vmrob commented Jan 27, 2014

Wow @rolandwalker, how funny you should explicitly mention me and virtualization, because I actually just happened to have a virtualized Mavericks install!

I can go ahead and test/verify this behavior right now.

@rolandwalker
Copy link
Contributor

@vmrob I realized what the bug is here, at least one of them, & I can patch it tonight/tmw. But if you are taking requests, a helpful piece of knowledge for adding a second failsafe would be the output of the following in a fresh VM

find /Library /System/Library -maxdepth 1 -type d

@vmrob
Copy link
Contributor

vmrob commented Jan 27, 2014

I can confirm this behavior on a fresh Mavericks install.

Log: https://gist.github.com/vmrob/8657159

@vmrob
Copy link
Contributor

vmrob commented Jan 27, 2014

As requested: https://gist.github.com/vmrob/8657231

rolandwalker added a commit to rolandwalker/homebrew-cask that referenced this issue Jan 28, 2014
This safety feature addresses Homebrew#2650 somewhat indirectly.
A list of system directories is defined.  When the uninstall
process encounters a "system directory" it does not touch that
directory at all
- no chmod on that dir
- no search for broken symlinks in that dir
- no cleanup of .DS_Store files in that dir
Explictly listed files from a pkg receipts are not affected by
this change.  Individual files will still be removed, even if
those files are in a special "system directory"
rolandwalker added a commit to rolandwalker/homebrew-cask that referenced this issue Jan 29, 2014
Fixes Homebrew#2650 (although there is more work to be done).  The issue is that
path.readlink.exist? returned false for all relative links, because readlink
reads relative to the current working directory.  This caused relative
symlinks such as /usr/bin/tar to be deleted, because package mosh identified
/usr/bin as one of its container directories.

The simplest fix is not to use readlink at all, because path.exist?
will tell us what we want to know, independent of current dir.
@rolandwalker
Copy link
Contributor

@wallacewinfrey this issue automatically closed itself because I merged a relevant fix into the master branch. However, the fix won't propagate out to you yet.

First we have to cut a new release of the code, then you will have to run brew update && brew upgrade brew-cask. I will ping you when the next release happens.

@rolandwalker
Copy link
Contributor

@wallacewinfrey I reviewed your list of delete commands and compared with a clean VM courtesy of @vmrob.

Below is a gist for a shell script which can replace most of your broken symlinks. Inside the script are comments for those cases that cannot be repaired by running the script. I realize you may have already finished your repairs, but this will be left up in case anyone else needs it.

mosh uninstall repair script

@rolandwalker
Copy link
Contributor

This bug is resolved for all users as of release v0.28.0.

Everyone is advised to brew update && brew upgrade brew-cask to avoid experiencing this bug.

@Homebrew Homebrew locked and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants