From f82ed2f33dede59e6044a5b42e7c5bec6f7bbe26 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 23 Jan 2013 00:26:25 -0600 Subject: FormulaInstaller: implement installation locks FormulaInstaller now attempts to take a lock on a "foo.brewing" file for the formula and all of its dependencies before attempting installation. The lock is an advisory lock implemented using flock(), and as such it only locks out other processes that attempt to take the lock. It also means that it is never necessary to manually remove the lock file, because the lock is not enforced by I/O. The uninstall, link, and unlink commands all learn to respect this lock as well, so that the installation cannot be corrupted by a concurrent Homebrew process, and keg operations cannot occur simultaneously. --- Library/Homebrew/cmd/link.rb | 6 ++++-- Library/Homebrew/cmd/uninstall.rb | 10 ++++++---- Library/Homebrew/cmd/unlink.rb | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew/cmd') diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index a85690ecb..6371c41de 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -35,8 +35,10 @@ module Homebrew extend self next end - print "Linking #{keg}... " do - puts "#{keg.link(mode)} symlinks created" + keg.lock do + print "Linking #{keg}... " do + puts "#{keg.link(mode)} symlinks created" + end end end end diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index d719be96a..19ad6eeb5 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -7,10 +7,12 @@ module Homebrew extend self if not ARGV.force? ARGV.kegs.each do |keg| - puts "Uninstalling #{keg}..." - keg.unlink - keg.uninstall - rm_opt_link keg.fname + keg.lock do + puts "Uninstalling #{keg}..." + keg.unlink + keg.uninstall + rm_opt_link keg.fname + end end else ARGV.named.each do |name| diff --git a/Library/Homebrew/cmd/unlink.rb b/Library/Homebrew/cmd/unlink.rb index 12b037781..37ef8f1da 100644 --- a/Library/Homebrew/cmd/unlink.rb +++ b/Library/Homebrew/cmd/unlink.rb @@ -3,8 +3,10 @@ module Homebrew extend self raise KegUnspecifiedError if ARGV.named.empty? ARGV.kegs.each do |keg| - print "Unlinking #{keg}... " - puts "#{keg.unlink} links removed" + keg.lock do + print "Unlinking #{keg}... " + puts "#{keg.unlink} links removed" + end end end end -- cgit v1.2.3