Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def cleanup_lockfiles
lockfiles = candidates.select(&:file?)
lockfiles.each do |file|
next unless file.readable?
file.open.flock(File::LOCK_EX | File::LOCK_NB) && file.unlink
file.open(File::RDWR).flock(File::LOCK_EX | File::LOCK_NB) && file.unlink
end
end

Expand Down
15 changes: 14 additions & 1 deletion Library/Homebrew/test/cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

describe Homebrew::Cleanup do
let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") }
let(:lock_file) { Pathname.new("#{HOMEBREW_LOCK_DIR}/foo") }
let(:sec_in_a_day) { 60 * 60 * 24 }

around(:each) do |example|
begin
FileUtils.touch ds_store
FileUtils.touch lock_file

example.run
ensure
FileUtils.rm_f ds_store
FileUtils.rm_f lock_file
end
end

describe "::cleanup" do
it "removes .DS_Store files" do
it "removes .DS_Store and lock files" do
described_class.cleanup

expect(ds_store).not_to exist
expect(lock_file).not_to exist
end

it "doesn't remove anything if `--dry-run` is specified" do
Expand All @@ -30,6 +34,15 @@
described_class.cleanup

expect(ds_store).to exist
expect(lock_file).to exist
end

it "doesn't remove the lock file if it is locked" do
lock_file.open(File::RDWR | File::CREAT).flock(File::LOCK_EX | File::LOCK_NB)

described_class.cleanup

expect(lock_file).to exist
end

context "when it can't remove a keg" do
Expand Down