core: clean up the lock cleanup code, tests
This commit is contained in:
parent
0ed3c5174b
commit
4fb9832589
|
@ -358,18 +358,13 @@ module Vagrant
|
||||||
return if !block_given?
|
return if !block_given?
|
||||||
|
|
||||||
# This allows multiple locks in the same process to be nested
|
# This allows multiple locks in the same process to be nested
|
||||||
return yield if @locks[name]
|
return yield if @locks[name] || opts[:noop]
|
||||||
|
|
||||||
# The path to this lock
|
# The path to this lock
|
||||||
lock_path = data_dir.join("lock.#{name}.lock")
|
lock_path = data_dir.join("lock.#{name}.lock")
|
||||||
|
|
||||||
@logger.debug("Attempting to acquire process-lock: #{name}")
|
@logger.debug("Attempting to acquire process-lock: #{name}")
|
||||||
|
lock("dotlock", noop: name == "dotlock") do
|
||||||
if name != "dotlock"
|
|
||||||
lock("dotlock", no_clean: true) do
|
|
||||||
f = File.open(lock_path, "w+")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
f = File.open(lock_path, "w+")
|
f = File.open(lock_path, "w+")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -398,8 +393,8 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clean up the lock file, this requires another lock
|
# Clean up the lock file, this requires another lock
|
||||||
if !opts[:no_clean]
|
if name != "dotlock"
|
||||||
lock("dotlock", no_clean: true) do
|
lock("dotlock") do
|
||||||
f.close
|
f.close
|
||||||
File.delete(lock_path)
|
File.delete(lock_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -198,6 +198,13 @@ describe Vagrant::Environment do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#lock" do
|
describe "#lock" do
|
||||||
|
def lock_count
|
||||||
|
subject.data_dir.
|
||||||
|
children.
|
||||||
|
find_all { |c| c.to_s.end_with?("lock") }.
|
||||||
|
length
|
||||||
|
end
|
||||||
|
|
||||||
it "does nothing if no block is given" do
|
it "does nothing if no block is given" do
|
||||||
subject.lock
|
subject.lock
|
||||||
end
|
end
|
||||||
|
@ -228,6 +235,19 @@ describe Vagrant::Environment do
|
||||||
|
|
||||||
expect(success).to be_true
|
expect(success).to be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "cleans up all lock files" do
|
||||||
|
inner_count = nil
|
||||||
|
|
||||||
|
expect(lock_count).to eq(0)
|
||||||
|
subject.lock do
|
||||||
|
inner_count = lock_count
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(inner_count).to_not be_nil
|
||||||
|
expect(inner_count).to eq(2)
|
||||||
|
expect(lock_count).to eq(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#machine" do
|
describe "#machine" do
|
||||||
|
|
Loading…
Reference in New Issue