mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
cleanup: fix removing lock files on NFS
If the underneath file system is a Network File System, `brew cleanup` will fail to remove the lock files with following error message: Error: Bad file descriptor @ rb_file_flock - /path/to/the/lock_file This commit fixes such issue and adds the corresponding test case.
This commit is contained in:
parent
c8533db23f
commit
d3fce64efb
@ -122,7 +122,7 @@ module Homebrew
|
|||||||
lockfiles = candidates.select(&:file?)
|
lockfiles = candidates.select(&:file?)
|
||||||
lockfiles.each do |file|
|
lockfiles.each do |file|
|
||||||
next unless file.readable?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,23 +5,27 @@ require "pathname"
|
|||||||
|
|
||||||
describe Homebrew::Cleanup do
|
describe Homebrew::Cleanup do
|
||||||
let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") }
|
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 }
|
let(:sec_in_a_day) { 60 * 60 * 24 }
|
||||||
|
|
||||||
around(:each) do |example|
|
around(:each) do |example|
|
||||||
begin
|
begin
|
||||||
FileUtils.touch ds_store
|
FileUtils.touch ds_store
|
||||||
|
FileUtils.touch lock_file
|
||||||
|
|
||||||
example.run
|
example.run
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_f ds_store
|
FileUtils.rm_f ds_store
|
||||||
|
FileUtils.rm_f lock_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::cleanup" do
|
describe "::cleanup" do
|
||||||
it "removes .DS_Store files" do
|
it "removes .DS_Store and lock files" do
|
||||||
described_class.cleanup
|
described_class.cleanup
|
||||||
|
|
||||||
expect(ds_store).not_to exist
|
expect(ds_store).not_to exist
|
||||||
|
expect(lock_file).not_to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't remove anything if `--dry-run` is specified" do
|
it "doesn't remove anything if `--dry-run` is specified" do
|
||||||
@ -30,6 +34,15 @@ describe Homebrew::Cleanup do
|
|||||||
described_class.cleanup
|
described_class.cleanup
|
||||||
|
|
||||||
expect(ds_store).to exist
|
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
|
end
|
||||||
|
|
||||||
context "when it can't remove a keg" do
|
context "when it can't remove a keg" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user