aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorXu Cheng2016-06-08 17:29:03 +0800
committerXu Cheng2016-06-08 17:29:03 +0800
commit8d64b6a02d78811f50d5f747ce10df09d54b4791 (patch)
treeba5b5f2691569591fb98c6a4a81c9c8ac676882e /Library/Homebrew
parent21ca138edf584daebf1795a52d6edd6ec34ce605 (diff)
downloadbrew-8d64b6a02d78811f50d5f747ce10df09d54b4791.tar.bz2
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`.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cleanup.rb6
-rw-r--r--Library/Homebrew/config.rb5
-rw-r--r--Library/Homebrew/formula_lock.rb2
-rw-r--r--Library/Homebrew/test/lib/config.rb1
-rw-r--r--Library/Homebrew/test/testing_env.rb2
-rw-r--r--Library/Homebrew/utils/lock.sh4
6 files changed, 13 insertions, 7 deletions
diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb
index 987020bc9..96689be11 100644
--- a/Library/Homebrew/cleanup.rb
+++ b/Library/Homebrew/cleanup.rb
@@ -106,9 +106,9 @@ module Homebrew
end
def self.cleanup_lockfiles
- return unless HOMEBREW_CACHE_FORMULA.directory?
- candidates = HOMEBREW_CACHE_FORMULA.children
- lockfiles = candidates.select { |f| f.file? && f.extname == ".brewing" }
+ return unless HOMEBREW_LOCK_DIR.directory?
+ candidates = HOMEBREW_LOCK_DIR.children
+ lockfiles = candidates.select(&:file?)
lockfiles.each do |file|
next unless file.readable?
file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink
diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb
index a7441059f..9635ffbae 100644
--- a/Library/Homebrew/config.rb
+++ b/Library/Homebrew/config.rb
@@ -1,7 +1,7 @@
HOMEBREW_CACHE = Pathname.new(ENV["HOMEBREW_CACHE"] || "~/Library/Caches/Homebrew").expand_path
# Where brews installed via URL are cached
-HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"
+HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE/"Formula"
if 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_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions"
+# Where we store lock files
+HOMEBREW_LOCK_DIR = HOMEBREW_LIBRARY/"Locks"
+
# Where we store built products
HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"])
diff --git a/Library/Homebrew/formula_lock.rb b/Library/Homebrew/formula_lock.rb
index 70b116d3c..25cacdb72 100644
--- a/Library/Homebrew/formula_lock.rb
+++ b/Library/Homebrew/formula_lock.rb
@@ -1,7 +1,7 @@
require "fcntl"
class FormulaLock
- LOCKDIR = HOMEBREW_CACHE_FORMULA
+ LOCKDIR = HOMEBREW_LOCK_DIR
def initialize(name)
@name = name
diff --git a/Library/Homebrew/test/lib/config.rb b/Library/Homebrew/test/lib/config.rb
index f6e601d52..10c3c8cd7 100644
--- a/Library/Homebrew/test/lib/config.rb
+++ b/Library/Homebrew/test/lib/config.rb
@@ -18,6 +18,7 @@ HOMEBREW_ENV_PATH = HOMEBREW_LIBRARY_PATH.parent+"ENV"
HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":")
HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache"
HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache"
+HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX.parent+"locks"
HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar"
HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs"
diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb
index b70b6cd6d..4e7089e42 100644
--- a/Library/Homebrew/test/testing_env.rb
+++ b/Library/Homebrew/test/testing_env.rb
@@ -7,7 +7,7 @@ require "formulary"
# Test environment setup
(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_DIRECTORY = File.dirname(File.expand_path(__FILE__))
diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh
index b8e3f61ad..4ff8dc060 100644
--- a/Library/Homebrew/utils/lock.sh
+++ b/Library/Homebrew/utils/lock.sh
@@ -3,7 +3,9 @@
# Noted due to the fixed FD, a shell process can only create one lock.
lock() {
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.
# This FD should be used exclusively for lock purpose.
# Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job.