Add per-cask/formula lockfile cleanup.

This commit is contained in:
Markus Reiter 2018-08-09 16:46:39 +02:00
parent 678ce2d7bd
commit bfd76a06ca
2 changed files with 12 additions and 4 deletions

View File

@ -174,11 +174,13 @@ module Homebrew
formula.eligible_kegs_for_cleanup.each(&method(:cleanup_keg)) formula.eligible_kegs_for_cleanup.each(&method(:cleanup_keg))
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*")) cleanup_cache(Pathname.glob(cache/"#{formula.name}--*"))
rm_ds_store([formula.rack]) rm_ds_store([formula.rack])
cleanup_lockfiles(FormulaLock.new(formula.name).path)
end end
def cleanup_cask(cask) def cleanup_cask(cask)
cleanup_cache(Pathname.glob(cache/"Cask/#{cask.token}--*")) cleanup_cache(Pathname.glob(cache/"Cask/#{cask.token}--*"))
rm_ds_store([cask.caskroom_path]) rm_ds_store([cask.caskroom_path])
cleanup_lockfiles(CaskLock.new(cask.token).path)
end end
def cleanup_keg(keg) def cleanup_keg(keg)
@ -230,13 +232,17 @@ module Homebrew
@disk_cleanup_size += disk_usage @disk_cleanup_size += disk_usage
end end
def cleanup_lockfiles def cleanup_lockfiles(*lockfiles)
return unless HOMEBREW_LOCK_DIR.directory? return unless HOMEBREW_LOCK_DIR.directory?
candidates = HOMEBREW_LOCK_DIR.children
lockfiles = candidates.select(&:file?) if lockfiles.empty?
lockfiles = HOMEBREW_LOCK_DIR.children.select(&:file?)
end
lockfiles.each do |file| lockfiles.each do |file|
next unless file.readable? next unless file.readable?
file.open(File::RDWR).flock(File::LOCK_EX | File::LOCK_NB) && file.unlink next unless file.open(File::RDWR).flock(File::LOCK_EX | File::LOCK_NB)
cleanup_path(file) { file.unlink }
end end
end end

View File

@ -1,6 +1,8 @@
require "fcntl" require "fcntl"
class LockFile class LockFile
attr_reader :path
def initialize(name) def initialize(name)
@name = name.to_s @name = name.to_s
@path = HOMEBREW_LOCK_DIR/"#{@name}.lock" @path = HOMEBREW_LOCK_DIR/"#{@name}.lock"