Merge pull request #4647 from reitermarkus/per-cask/formula-ds_store-cleanup
Per cask/formula `.DS_Store` cleanup
This commit is contained in:
commit
5198ad4277
@ -5,6 +5,30 @@ require "hbc/cask_loader"
|
|||||||
module CleanupRefinement
|
module CleanupRefinement
|
||||||
LATEST_CASK_DAYS = 7
|
LATEST_CASK_DAYS = 7
|
||||||
|
|
||||||
|
refine Enumerator do
|
||||||
|
def parallel
|
||||||
|
queue = Queue.new
|
||||||
|
|
||||||
|
each do |element|
|
||||||
|
queue.enq(element)
|
||||||
|
end
|
||||||
|
|
||||||
|
workers = (0...Hardware::CPU.cores).map do
|
||||||
|
Thread.new do
|
||||||
|
Kernel.loop do
|
||||||
|
begin
|
||||||
|
yield queue.deq(true)
|
||||||
|
rescue ThreadError
|
||||||
|
break # if queue is empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
workers.each(&:join)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
refine Pathname do
|
refine Pathname do
|
||||||
def incomplete?
|
def incomplete?
|
||||||
extname.end_with?(".incomplete")
|
extname.end_with?(".incomplete")
|
||||||
@ -149,10 +173,14 @@ module Homebrew
|
|||||||
def cleanup_formula(formula)
|
def cleanup_formula(formula)
|
||||||
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])
|
||||||
|
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])
|
||||||
|
cleanup_lockfiles(CaskLock.new(cask.token).path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_keg(keg)
|
def cleanup_keg(keg)
|
||||||
@ -204,32 +232,27 @@ 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
|
||||||
|
|
||||||
def rm_ds_store
|
def rm_ds_store(dirs = nil)
|
||||||
paths = Queue.new
|
dirs ||= %w[Caskroom Cellar Frameworks Library bin etc include lib opt sbin share var]
|
||||||
%w[Cellar Frameworks Library bin etc include lib opt sbin share var]
|
.map { |path| HOMEBREW_PREFIX/path }
|
||||||
.map { |p| HOMEBREW_PREFIX/p }.each { |p| paths << p if p.exist? }
|
|
||||||
workers = (0...Hardware::CPU.cores).map do
|
dirs.select(&:directory?).each.parallel do |dir|
|
||||||
Thread.new do
|
system_command "find", args: [dir, "-name", ".DS_Store", "-delete"], print_stderr: false
|
||||||
Kernel.loop do
|
|
||||||
begin
|
|
||||||
quiet_system "find", paths.deq(true), "-name", ".DS_Store", "-delete"
|
|
||||||
rescue ThreadError
|
|
||||||
break # if queue is empty
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
workers.map(&:join)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
@ -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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user