Merge pull request #3921 from xu-cheng/cleanup-nfs

cleanup: fix removing lock files on NFS
This commit is contained in:
Mike McQuaid 2018-03-14 14:05:41 +00:00 committed by GitHub
commit c933247a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -122,7 +122,7 @@ module Homebrew
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

View File

@ -5,23 +5,27 @@ require "pathname"
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
@ -30,6 +34,15 @@ describe Homebrew::Cleanup do
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