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

Catch permission errors when doing brew cleanup #4989

Closed
MikeLund opened this issue Sep 26, 2018 · 9 comments
Closed

Catch permission errors when doing brew cleanup #4989

MikeLund opened this issue Sep 26, 2018 · 9 comments
Labels
features New features outdated PR was locked due to age

Comments

@MikeLund
Copy link

Hello,

When running brew cleanup, it was unable to delete some files in my PHP install (I guess that I stupidly ran PHP as a different user at some point or something, so that var/logs directory has files that my user couldn't delete).

Removing: /usr/local/Cellar/php@7.0/7.0.30... (502 files, 65.6MB)
Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/php@7.0/7.0.30
~$

Due to this error, it terminated the brew process, instead of continuing until the end -- and so I lost the ability to easily see how much disk space I regained from running cleanup in the first place.

Suggestion: catch these types of errors, so brew process will continue as normal, proceeding to the next formula in cleanup. Alternatively, if there is some legitimate reason for brew to fully stop processing when this type of error happens, it should still print the wonderful This operation has freed approximately xx GB of disk space message.

So not a major problem, but I thought it would be a useful idea in the future. Thanks for your time.

@MikeMcQuaid
Copy link
Member

Please fill in the issue template i.e. provide your brew config and brew doctor output.

@MikeLund
Copy link
Author

Sorry, I didn't think that was necessary because it's not really a bug with Brew, but a suggestion that it should catch errors (in my case, a permission error that was almost certainly my fault) when doing cleanup.

I had to use sudo to delete the /usr/local/Cellar/php@7.0/7.0.30 because my user didn't have permissions to delete a log file in there, so it's expected that brew running as my normal user wouldn't have had permissions to delete it either.

~$ brew config
HOMEBREW_VERSION: 1.7.6-20-gbb177b3
ORIGIN: https://github.com/Homebrew/brew
HEAD: bb177b305596748625ffdbbbe5e523495aca7305
Last commit: 25 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 03c0cf6b5b9b4cb45959fa735a9f610b68a67e00
Core tap last commit: 20 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_DEV_CMD_RUN: 1
HOMEBREW_NO_ANALYTICS_THIS_RUN: 1
CPU: octa-core 64-bit haswell
Homebrew Ruby: 2.3.7 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/bin/ruby
Clang: 10.0 build 1000
Git: 2.19.0 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: 10, 1.8.0_162
macOS: 10.14-x86_64
CLT: N/A
Xcode: 10.0
XQuartz: 2.7.11 => /opt/X11
~$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  ghostscript
  php
  mono

I can't reproduce it anymore because I already manually deleted those folders as root (and my brew is 100% clean now), but I imagine it would be reproducible if you create a folder+file that's only modifiable by root in one of the Cellar's versions, and then try to run cleanup.

Hope this helps explain the situation and I didn't forget to include anything.

@MikeMcQuaid
Copy link
Member

I imagine it would be reproducible if you create a folder+file that's only modifiable by root in one of the Cellar's versions, and then try to run cleanup.

Could you try that and also include your brew doctor output if/when you can reproduce it? Ideally provide reproduction step commands in here. Thanks!

@MikeLund
Copy link
Author

mujs updated to 1.0.5 now, so I got to use 1.0.4 to demo. Hopefully I'm making it clear that the whole situation is caused by PEBKAC: user creating files in the Cellar that's not able to be deleted by the user invoking brew.

Instructions:

sudo -i (this is the only important part, needed so files created won't be able to be deleted by brew-invoker)
cd /usr/local/Cellar/mujs/1.0.4
mkdir var
touch var/test.log
exit

Now, gives error on cleanup, and doctor is same as before:

~$ brew cleanup
Removing: /usr/local/Cellar/mujs/1.0.4... (10 files, 510.6KB)
Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/mujs/1.0.4
~$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  ghostscript
  php
  mono

Permissions on this stuff:

~$ ls -alh /usr/local/Cellar/mujs/1.0.4/
total 16
drwxr-xr-x  6 mikelund  staff   192B Sep 27 16:25 .
drwxr-xr-x  4 mikelund  staff   128B Sep 27 16:19 ..
-rw-r--r--  1 mikelund  staff   755B Jul 30 15:35 COPYING
-rw-r--r--  1 mikelund  staff   1.6K Aug 26 04:42 README
drwxr-xr-x  4 mikelund  staff   128B Jul 30 15:35 lib
drwxr-xr-x  3 root      staff    96B Sep 27 16:25 var
~$ ls -alh /usr/local/Cellar/mujs/1.0.4/var/
total 0
drwxr-xr-x  3 root      staff    96B Sep 27 16:25 .
drwxr-xr-x  6 mikelund  staff   192B Sep 27 16:25 ..
-rw-r--r--  1 root      staff     0B Sep 27 16:25 test.log

If I fix those permissions (take ownership of that folder and file -- which was created earlier by me -- to my user), brew cleanup runs fine:

~$ brew cleanup
Removing: /usr/local/Cellar/mujs/1.0.4... (5 files, 297.7KB)
Removing: /Users/mikelund/Library/Caches/Homebrew/mujs--1.0.4.high_sierra.bottle.tar.gz... (211KB)
==> This operation has freed approximately 508.7KB of disk space.

@MikeMcQuaid MikeMcQuaid added bug Reproducible Homebrew/brew bug help wanted We want help addressing this labels Sep 30, 2018
@amyspark
Copy link
Contributor

amyspark commented Oct 2, 2018

Does Homebrew have utilities to regain file ownership en masse? Cask does in the Staged module.

@MikeMcQuaid MikeMcQuaid added this to Help Wanted in Homebrew TODO Oct 3, 2018
@steinmb
Copy link

steinmb commented Oct 29, 2018

Also noticed the same. var directory was owned by root. Cleanup of PHP 5.6.x and 7.1.x

brew doctor

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  php53

brew config

HOMEBREW_VERSION: 1.8.0
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: fdd8e9b7cf1e53322492e1e90f685c19bdfde506
Last commit: 8 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: a5e7728216e0c825dbe6ee347b1432dada577eca
Core tap last commit: 3 hours ago
HOMEBREW_PREFIX: /usr/local
CPU: quad-core 64-bit broadwell
Homebrew Ruby: 2.3.7 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 10.0 build 1000
Git: 2.17.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
macOS: 10.13.6-x86_64
CLT: 10.0.0.0.1.1535735448
Xcode: 10.0
XQuartz: 2.7.11 => /opt/X11

@MikeMcQuaid
Copy link
Member

@steinmb Please avoid "me too" comments; this will apply to everyone. Thanks!

@MikeMcQuaid MikeMcQuaid added features New features and removed bug Reproducible Homebrew/brew bug help wanted We want help addressing this labels Dec 21, 2018
@nikhiljha
Copy link

All of my python installs are doing the same thing

Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/python/2.7.13_1

but when I rerun brew cleanup it works. Maybe brew can try again once if it fails for whatever reason?

@MikeMcQuaid
Copy link
Member

@nikhiljha That's a different issue. Please open a new issue for it, fill out the issue template and ideally run the relevant command with a --debug argument. Thanks!

Homebrew TODO automation moved this from Help Wanted to Done Jan 28, 2019
@lock lock bot added the outdated PR was locked due to age label Feb 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
features New features outdated PR was locked due to age
Projects
Homebrew TODO
  
Done
Development

No branches or pull requests

5 participants