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`.
This commit is contained in:
parent
21ca138edf
commit
8d64b6a02d
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,6 +15,7 @@
|
|||||||
/Library/Homebrew/test/coverage
|
/Library/Homebrew/test/coverage
|
||||||
/Library/Homebrew/test/fs_leak_log
|
/Library/Homebrew/test/fs_leak_log
|
||||||
/Library/LinkedKegs
|
/Library/LinkedKegs
|
||||||
|
/Library/Locks
|
||||||
/Library/PinnedKegs
|
/Library/PinnedKegs
|
||||||
/Library/PinnedTaps
|
/Library/PinnedTaps
|
||||||
/Library/Taps
|
/Library/Taps
|
||||||
|
|||||||
@ -106,9 +106,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.cleanup_lockfiles
|
def self.cleanup_lockfiles
|
||||||
return unless HOMEBREW_CACHE_FORMULA.directory?
|
return unless HOMEBREW_LOCK_DIR.directory?
|
||||||
candidates = HOMEBREW_CACHE_FORMULA.children
|
candidates = HOMEBREW_LOCK_DIR.children
|
||||||
lockfiles = candidates.select { |f| f.file? && f.extname == ".brewing" }
|
lockfiles = candidates.select(&:file?)
|
||||||
lockfiles.each do |file|
|
lockfiles.each do |file|
|
||||||
next unless file.readable?
|
next unless file.readable?
|
||||||
file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink
|
file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
HOMEBREW_CACHE = Pathname.new(ENV["HOMEBREW_CACHE"] || "~/Library/Caches/Homebrew").expand_path
|
HOMEBREW_CACHE = Pathname.new(ENV["HOMEBREW_CACHE"] || "~/Library/Caches/Homebrew").expand_path
|
||||||
|
|
||||||
# Where brews installed via URL are cached
|
# Where brews installed via URL are cached
|
||||||
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"
|
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE/"Formula"
|
||||||
|
|
||||||
if ENV["HOMEBREW_BREW_FILE"]
|
if ENV["HOMEBREW_BREW_FILE"]
|
||||||
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"])
|
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"])
|
||||||
@ -19,6 +19,9 @@ HOMEBREW_LIBRARY = Pathname.new(ENV["HOMEBREW_LIBRARY"])
|
|||||||
HOMEBREW_ENV_PATH = HOMEBREW_LIBRARY/"ENV"
|
HOMEBREW_ENV_PATH = HOMEBREW_LIBRARY/"ENV"
|
||||||
HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions"
|
HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions"
|
||||||
|
|
||||||
|
# Where we store lock files
|
||||||
|
HOMEBREW_LOCK_DIR = HOMEBREW_LIBRARY/"Locks"
|
||||||
|
|
||||||
# Where we store built products
|
# Where we store built products
|
||||||
HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"])
|
HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"])
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
require "fcntl"
|
require "fcntl"
|
||||||
|
|
||||||
class FormulaLock
|
class FormulaLock
|
||||||
LOCKDIR = HOMEBREW_CACHE_FORMULA
|
LOCKDIR = HOMEBREW_LOCK_DIR
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name
|
@name = name
|
||||||
|
|||||||
@ -18,6 +18,7 @@ HOMEBREW_ENV_PATH = HOMEBREW_LIBRARY_PATH.parent+"ENV"
|
|||||||
HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":")
|
HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":")
|
||||||
HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache"
|
HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache"
|
||||||
HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache"
|
HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache"
|
||||||
|
HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX.parent+"locks"
|
||||||
HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar"
|
HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar"
|
||||||
HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs"
|
HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs"
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ require "formulary"
|
|||||||
|
|
||||||
# Test environment setup
|
# Test environment setup
|
||||||
(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-core/Formula").mkpath
|
(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-core/Formula").mkpath
|
||||||
%w[cache formula_cache cellar logs].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath }
|
%w[cache formula_cache locks cellar logs].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath }
|
||||||
|
|
||||||
# Test fixtures and files can be found relative to this path
|
# Test fixtures and files can be found relative to this path
|
||||||
TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__))
|
TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__))
|
||||||
|
|||||||
@ -3,7 +3,9 @@
|
|||||||
# Noted due to the fixed FD, a shell process can only create one lock.
|
# Noted due to the fixed FD, a shell process can only create one lock.
|
||||||
lock() {
|
lock() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local lock_file="/tmp/homebrew${HOMEBREW_REPOSITORY//\//-}-${name}.lock"
|
local lock_dir="$HOMEBREW_LIBRARY/Locks"
|
||||||
|
local lock_file="$lock_dir/$name"
|
||||||
|
[[ -d "$lock_dir" ]] || mkdir -p "$lock_dir"
|
||||||
# 200 is the file descriptor used in the lock.
|
# 200 is the file descriptor used in the lock.
|
||||||
# This FD should be used exclusively for lock purpose.
|
# This FD should be used exclusively for lock purpose.
|
||||||
# Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job.
|
# Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user