18 Commits

Author SHA1 Message Date
Mike McQuaid
e3a1a9dccf
Improve locking UX
My experience recently playing around with our locking behaviour is
that, while mostly seamless and not seen by users, it's leaks
implementation details a bit too heavily.

As a result, the following improvements are in this commit:
- Ensure that, whenever possible, we tell the user the actual command
  that is holding a given lock instead of the lock name (an internal
  implementation detail)
- Make the locking error output a little more consistent and user
  friendly
- Add a `DownloadLock` class to simplify locking downloads
- Add a `HOMEBREW_LOCK_CONTEXT` variable to allow adding additional
  context for logging error messages
- Lock paths and leave deciding how this translates to lock names up
  to the locking code itself
- Lock the Cellar/Caskroom paths explicitly rather than implicitly

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-07-30 17:51:02 +01:00
Mike McQuaid
bc0f5ee62a
Library/Homebrew: move stdin ruby scripts to files under utils.
This avoids can avoid UID/EUID related issues with Ruby scripts passed
over `stdin` clashing with Ruby security features.

It's also just a bit nicer to have Ruby scripts in files instead.

While we're here:
- refactor some shared logic into a new `setup-gem-home-bundle-gemfile`
  function in `ruby.sh`
- do some general cleanup of `lock.sh`
- prioritise `flock` over `python` in `lock.sh`
2024-05-02 10:33:42 +01:00
Bo Anderson
636d883008
Support bash in privileged mode 2024-03-27 04:40:44 +00:00
Mike McQuaid
39bbc33a27
Improve use of whoami
If you're e.g. running Homebrew over `sudo`: shelling out to `whoami`
is less effective than just telling people which user you're running
as when we run the check.
2023-09-29 12:32:22 +01:00
XuehaiPan
3f96d963f7 style: fix inconsistent code style for shell scripts 2021-09-15 14:59:01 +08:00
hyuraku
05260f4565 utils/lock.sh: repair style 2021-04-21 20:51:50 +09:00
okhowang(王沛文)
d959a780d4 use python flock firstly 2019-02-26 14:19:12 +08:00
Buck Evan
0a2e649f00 type -P is more portable than which
Migrated from https://github.com/Linuxbrew/brew/pull/621
2018-03-18 16:51:22 -07:00
Michka Popoff
b93ed4124c lock.sh: suppress error output when looking for flock
Fixes (on centos6):
which: no flock in (/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
2017-10-27 15:54:24 +02:00
Misty De Meo
67dc3323ed
lock: simplify ruby conditional 2017-05-24 09:12:21 -07:00
Misty De Meo
94ed3e3583
lock: check tools are executable 2017-05-23 18:36:06 -07:00
Misty De Meo
129ee966f8 Optionally use Python's flock instead of Ruby's
Ruby first gained flock in 1.8.7, which is a problem since we're using
this lock utility in `vendor-install` in order to install a newer Ruby.

Fortunately, Python 2.3(!) has flock support.
2017-05-23 17:50:22 -07:00
Mike McQuaid
9edf8eb1fe Check the lock directory is writable.
And, if it isn't, print more helpful debugging messages.

Fixes #1456.
2016-11-11 22:52:21 +00:00
Mike McQuaid
e3609b6fd4 Move LinkedKegs/PinnedKegs/Locks from Library.
These don't make sense to be tied to the `HOMEBREW_REPOSITORY` but
instead should live in the `HOMEBREW_PREFIX` as they all relate to its
state.
2016-09-16 13:51:56 +01:00
Martin Afanasjew
1c27a75ca4 utils/lock.sh: remove redundant 'local' 2016-06-29 22:38:42 +02:00
Xu Cheng
8d64b6a02d introduce global lock directory (#337)
Since #292, HOMEBREW_CACHE was moved to a per-user directory. This makes
it unsuitable to store global lock files on multiple users environment.

Therefore, introducing a global lock directory `/Library/Lock.d` to
store lock files from formula lockers as well as `brew update`.
2016-06-08 17:29:03 +08:00
Mike McQuaid
8ecfab8a59 utils/lock.sh: default to system Ruby if available (#271)
This avoids weird issues with custom Rubies.

Closes #253.
2016-05-23 14:36:25 +01:00
Xu Cheng
ad8f50ec6d add utils/lock.sh
a Bash implementation of lock using `flock(2)`.
2016-05-12 15:36:46 +08:00