132 Commits

Author SHA1 Message Date
apainintheneck
f068f74f55 Move autoremove code to util and add tests 2022-09-13 23:23:48 -07:00
Carlo Cabrera
55f27b932a
Merge pull request #13715 from carlocab/python-site-packages
cleanup: handle Python `site-packages` directories
2022-08-31 21:08:14 +08:00
Carlo Cabrera
155f4d7394
Fix collection of unused_pyc_files. 2022-08-31 16:04:21 +08:00
apainintheneck
98e6e6e31f Ignore HOMEBREW_NO_CLEANUP_FORMULAE deps in brew autoremove 2022-08-22 20:10:14 -07:00
Carlo Cabrera
7384bd2b3f
cleanup: use cleanup_path more consistently
`cleanup_path` already handles the dry-run logic, and also includes
those paths in the summary of space freed by `brew cleanup`.

Before this change:

    ❯ brew cleanup --dry-run
    Would remove: /Users/carlocab/Library/Caches/Homebrew/bootsnap (2,401 files, 41.9MB)

After this change:

    ❯ brew cleanup --dry-run
    Would remove: /Users/carlocab/Library/Caches/Homebrew/bootsnap (2,401 files, 41.9MB)
    ==> This operation would free approximately 41.9MB of disk space.
2022-08-18 21:28:51 +08:00
Carlo Cabrera
0b48261f79
cleanup: handle Python site-packages directories
Inside a given `site-packages` directory, *.pyc files live in
`__pycache__` directories. These are created by the Python interpreter
when a module is imported in order to speed up future access to the
imported module.

These can be left behind when formulae are uninstalled, which results in
erroneous success in importing the modules they were originally compiled
for.

Let's fix that by cleaning these up. In the top-level `__pycache__`
directory, we use the `Pathname#prune?` extension in order to determine
whether a `*.pyc` file is old enough to clean up. In other directories,
we clean them up when they are all that remains in a given module's
tree.

Removing these `*.pyc` files will make `python3` regenerate them when
required, so deleting them is relatively safe. The worst consequence is
slightly slower module import times.

Closes #13701.
2022-08-18 21:09:12 +08:00
fn ⌃ ⌥
dce57eaad6 Always print install cleanup disable message for periodic clean 2022-08-04 07:46:31 -07:00
fn ⌃ ⌥
71ab2f6e7a Run periodic cleanup after installing all packages 2022-08-04 07:46:31 -07:00
apainintheneck
cb91f8b665 Add tests for retrieving formula based on dependents
Also, made sure to clear formula cache before
and after autoremoving packages.
2022-07-17 00:39:23 -07:00
apainintheneck
fe83500617 Moved autoremove logic into cleanup.rb and formula.rb
Cleanup.rb:
- Added #autoremove method
- #autoremove is called in clean when HOMEBREW_AUTOREMOVE is set

Formula.rb:
- Added #unused_formulae_with_no_dependents and helpers

Removed old autoremove.rb module.
2022-07-14 13:16:26 -07:00
Bo Anderson
02164a35db
Use ORIGINAL_PATHS over envs; reject nil PATH 2022-06-17 19:47:57 +01:00
Émilia Decaudin
6642801b04 Show total disk space freed on cleanup. 2022-03-07 12:25:27 -05:00
Mike McQuaid
5ebf3acc94
Revert "cleanup: check if symlinks are readable." 2022-01-25 12:10:50 +00:00
Mike McQuaid
f3619134c2
cleanup: check if symlinks are readable. 2022-01-20 12:21:56 +00:00
Mike McQuaid
6913c7c84e
Output environment variable hints.
Output hints for disabling automatic `brew update`, `brew cleanup` and
`brew upgrade`/`brew reinstall` of dependents. Also provide a
`HOMEBREW_NO_ENV_HINTS` to disable this messaging.
2021-11-26 13:14:10 +00:00
Mike McQuaid
11c5f8f05a
Improve discovery of some environment variables
There's a few bits of functionality that Homebrew has changed over the
years, makes sense as a sensible default but some people find really
annoying:

- automatically running `brew update`
- automatically running `brew cleanup`
- automatically upgrading outdated dependents
- automatically reinstalling broken dependents

For each of these: let's improve the documentation of the commands
whose behaviour is changed and the environment variables themselves.
2021-11-25 09:10:59 +00:00
Kaito Udagawa
6b5f912a3a Catch ENOTEMPTY in cleanup_keg
#11904
2021-10-19 23:39:58 +09:00
EricFromCanada
c234d1ea03
upgrade: list upgradeable dependencies/migrations/cleanups on dry run 2021-08-31 12:27:14 -04:00
Carlo Cabrera
a7133d2a8d
cleanup: allow users to specify formulae to skip cleaning
This allows users to set `HOMEBREW_NO_CLEANUP_FORMULAE` to a
comma-separated list of formulae that `brew` will refuse to clean with
`brew cleanup`.

We currently allow a less granular version of this with
`HOMEBREW_NO_INSTALL_CLEANUP`. All this changes is how much control
users have over what is and isn't cleaned.

Fixes #11924.
2021-08-27 18:21:19 +08:00
John Bampton
1691e615fe Fix spelling 2021-05-08 11:20:01 +10:00
Mike McQuaid
1cb082db94
cleanup: ignore DS_Store access failures.
Fixes #10988.
2021-04-23 14:49:12 +01:00
Mike McQuaid
d8a2cf9efc
Write tabs to bottle JSON, optionally not bottle
- Write a subset of the tab required for bottles as an annotation.
- Add option on new bottle creation to skip writing tab into bottle
  and instead add it (and other useful metadata) to bottle JSON.
- Read formula information and tab from bottle JSON.
- Write prettier JSON to disk.
- Don't write `HEAD` to tab; this duplicates `HOMEBREW_VERSION`.
- Allow `brew bottle` to use `--json` to generate JSON files from a
  local bottle file.
2021-03-31 09:43:37 +01:00
Bo Anderson
450bc4ab33
Fix brew style 2021-03-26 14:11:03 +00:00
Bo Anderson
1fba9b9b53
Prevent loading all non-Bundler gems 2021-02-26 18:23:48 +00:00
nandahkrishna
8e5451df2f
style: use parentheses for assignment in conditions 2021-02-12 18:33:37 +05:30
Mike McQuaid
36c292f278
cleanup: cleanup bootsnap files. 2021-02-02 12:34:15 +00:00
Mike McQuaid
15761a283d
cleanup: raise failures and handle later.
These are already handled and outputted as a group in `cmd/cleanup.rb`.

Fixes https://github.com/Homebrew/brew/issues/10379
2021-01-21 13:03:52 +00:00
Michka Popoff
5e91802470 checksum: simplify, use only sha256
We use only one sha type right now.

Needed for https://github.com/Homebrew/brew/pull/10186
2021-01-07 20:46:13 +01:00
Mike McQuaid
0d76400a80
cleanup: don't do stale check when passing --prune.
This speeds up `--prune` fairly considerably.

Before:
```
$ hyperfine --warmup 3 'brew cleanup --prune=365'
Benchmark #1: brew cleanup --prune=365
  Time (mean ± σ):     33.352 s ±  0.654 s    [User: 21.684 s, System: 6.458 s]
  Range (min … max):   31.901 s … 34.096 s    10 runs
```

After:
```
$ hyperfine --warmup 3 'brew cleanup --prune=365'
Benchmark #1: brew cleanup --prune=365
  Time (mean ± σ):      6.821 s ±  0.186 s    [User: 2.225 s, System: 3.926 s]
  Range (min … max):    6.578 s …  7.178 s    10 runs
```

Closes https://github.com/Homebrew/brew/pull/10177/
Fixes https://github.com/Homebrew/brew/issues/10172
2020-12-31 14:00:12 +00:00
Mike McQuaid
4f438f6e45
Merge pull request #9477 from MikeMcQuaid/cleanup_periodic_full_days
Add HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS environment variable
2020-12-10 12:57:08 +00:00
Mike McQuaid
adab0fbb41
cleanup: fix portable Ruby behaviour.
Better match the macOS behaviour in `ruby.sh`.

Fixes #9469
2020-12-09 11:50:45 +00:00
Mike McQuaid
5757777a6e
Add HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS environment variable
This allows customisation of how often the periodic cleanups are done.
2020-12-09 10:36:02 +00:00
Mike McQuaid
9216d8abe6
rubocop-rails: make fixes. 2020-12-02 10:43:04 +00:00
EricFromCanada
19a382570c cleanup.rb: ensure cache exists before touching .cleaned 2020-11-14 10:48:10 -05:00
Jonathan Chang
500908ee6f rubocop: fix Lint/NoReturnInBeginEndBlocks 2020-11-10 23:28:31 +11:00
EricFromCanada
3768b7a6e9 apidoc: update comment wording, punctuation, formatting 2020-11-06 00:21:02 -05:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Mike McQuaid
3d436d3664 Improve linkage cache linkage_cache_performance
- Use reference counting so nested `CacheStoreDatabase.use` share the
  same underlying database (rather than rereading it every time).
- Only write out the cache database file when it has changed.
- Cleanup cache database entries on formula or full `brew cleanup`.

Fixes #8690
2020-09-11 12:57:15 +01:00
Maxim Belkin
896c93b819 cleanup.rb: quiet down Ruby test 2020-09-03 17:24:25 +00:00
Maxim Belkin
a6d29894d9 cleanup: fix and reuse portable ruby logic.
Align the logic in `cleanup_portable_ruby` with that in `ruby.sh`.

Co-authored-by: Maxim Belkin <maxim.belkin@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-09-03 09:43:41 +01:00
Mike McQuaid
8b97c27c21 brew style manual fixes 2020-09-01 14:26:45 +01:00
Mike McQuaid
3a91c37e66
Fix RuboCop checks. 2020-08-19 17:12:32 +01:00
Markus Reiter
5402500635 Refactor and document Cleanup. 2020-08-17 19:11:31 +02:00
Bo Anderson
3205ace13e cleanup: clean go_mod_cache 2020-07-20 15:30:33 +01:00
Mike McQuaid
4816e8320d
cleanup: check path exists before cleanup.
It may have been already cleaned up by an earlier step.
2020-07-10 09:32:27 +01:00
Mike McQuaid
f951ea83d4
Fix brew style. 2020-07-07 12:23:29 +01:00
Mike McQuaid
aa81982aba
brew style --fix 2020-06-02 09:49:23 +01:00
Mike McQuaid
4f75a77b08
Update deprecations
Add more deprecations, disable deprecations and remove disabled code.
2020-05-18 13:50:46 +01:00
Mike McQuaid
4da5c09c25
cleanup: tweak missing clean file behaviour.
Instead of cleaning every time if the file is missing: don't clean this
time, touch the file and clean when it's next needed.

Now that this feature has been around for longer this makes more sense
for existing installations and stops the first `brew install` run on a
new/test installation without this file always running a `brew cleanup`.

Also, fix up the use of a compat/deprecated method hit by tests by
this change.
2020-05-07 11:01:09 +01:00
Mike McQuaid
701c1811d5
cleanup: all configuring max age days.
Fixes #7320
2020-04-20 10:33:15 +01:00