Skip to content
Snippets Groups Projects
Unverified Commit 5198ad42 authored by Markus Reiter's avatar Markus Reiter Committed by GitHub
Browse files

Merge pull request #4647 from reitermarkus/per-cask/formula-ds_store-cleanup

Per cask/formula `.DS_Store` cleanup
parents 8e703e30 bfd76a06
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,30 @@ require "hbc/cask_loader"
module CleanupRefinement
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
def incomplete?
extname.end_with?(".incomplete")
......@@ -149,10 +173,14 @@ module Homebrew
def cleanup_formula(formula)
formula.eligible_kegs_for_cleanup.each(&method(:cleanup_keg))
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*"))
rm_ds_store([formula.rack])
cleanup_lockfiles(FormulaLock.new(formula.name).path)
end
def cleanup_cask(cask)
cleanup_cache(Pathname.glob(cache/"Cask/#{cask.token}--*"))
rm_ds_store([cask.caskroom_path])
cleanup_lockfiles(CaskLock.new(cask.token).path)
end
def cleanup_keg(keg)
......@@ -204,32 +232,27 @@ module Homebrew
@disk_cleanup_size += disk_usage
end
def cleanup_lockfiles
def cleanup_lockfiles(*lockfiles)
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|
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
def rm_ds_store
paths = Queue.new
%w[Cellar Frameworks Library bin etc include lib opt sbin share var]
.map { |p| HOMEBREW_PREFIX/p }.each { |p| paths << p if p.exist? }
workers = (0...Hardware::CPU.cores).map do
Thread.new do
Kernel.loop do
begin
quiet_system "find", paths.deq(true), "-name", ".DS_Store", "-delete"
rescue ThreadError
break # if queue is empty
end
end
end
def rm_ds_store(dirs = nil)
dirs ||= %w[Caskroom Cellar Frameworks Library bin etc include lib opt sbin share var]
.map { |path| HOMEBREW_PREFIX/path }
dirs.select(&:directory?).each.parallel do |dir|
system_command "find", args: [dir, "-name", ".DS_Store", "-delete"], print_stderr: false
end
workers.map(&:join)
end
end
end
require "fcntl"
class LockFile
attr_reader :path
def initialize(name)
@name = name.to_s
@path = HOMEBREW_LOCK_DIR/"#{@name}.lock"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment