core: delete environment lock files
This commit is contained in:
parent
84f889e801
commit
0ed3c5174b
|
@ -352,6 +352,8 @@ module Vagrant
|
||||||
# @param [String] name Name of the lock, since multiple locks can
|
# @param [String] name Name of the lock, since multiple locks can
|
||||||
# be held at one time.
|
# be held at one time.
|
||||||
def lock(name="global", **opts)
|
def lock(name="global", **opts)
|
||||||
|
f = nil
|
||||||
|
|
||||||
# If we don't have a block, then locking is useless, so ignore it
|
# If we don't have a block, then locking is useless, so ignore it
|
||||||
return if !block_given?
|
return if !block_given?
|
||||||
|
|
||||||
|
@ -362,7 +364,15 @@ module Vagrant
|
||||||
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}")
|
||||||
File.open(lock_path, "w+") do |f|
|
|
||||||
|
if name != "dotlock"
|
||||||
|
lock("dotlock", no_clean: true) do
|
||||||
|
f = File.open(lock_path, "w+")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
f = File.open(lock_path, "w+")
|
||||||
|
end
|
||||||
|
|
||||||
# The file locking fails only if it returns "false." If it
|
# The file locking fails only if it returns "false." If it
|
||||||
# succeeds it returns a 0, so we must explicitly check for
|
# succeeds it returns a 0, so we must explicitly check for
|
||||||
# the proper error case.
|
# the proper error case.
|
||||||
|
@ -374,17 +384,33 @@ module Vagrant
|
||||||
|
|
||||||
@logger.info("Acquired process lock: #{name}")
|
@logger.info("Acquired process lock: #{name}")
|
||||||
|
|
||||||
|
result = nil
|
||||||
begin
|
begin
|
||||||
# Mark that we have a lock
|
# Mark that we have a lock
|
||||||
@locks[name] = true
|
@locks[name] = true
|
||||||
|
|
||||||
return yield
|
result = yield
|
||||||
ensure
|
ensure
|
||||||
# We need to make sure that no matter what this is always
|
# We need to make sure that no matter what this is always
|
||||||
# reset to false so we don't think we have a lock when we
|
# reset to false so we don't think we have a lock when we
|
||||||
# actually don't.
|
# actually don't.
|
||||||
@locks.delete(name)
|
@locks.delete(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clean up the lock file, this requires another lock
|
||||||
|
if !opts[:no_clean]
|
||||||
|
lock("dotlock", no_clean: true) do
|
||||||
|
f.close
|
||||||
|
File.delete(lock_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return the result
|
||||||
|
return result
|
||||||
|
ensure
|
||||||
|
begin
|
||||||
|
f.close if f
|
||||||
|
rescue IOError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue