Sha256: c6dc4d44fdd6f81e81a77e663df8f5f3713b4eb6dba3f32a6b9a0941c3b4e316
Contents?: true
Size: 821 Bytes
Versions: 75
Compression:
Stored size: 821 Bytes
Contents
require 'thread' module Vagrant module Util class SafeChdir @@chdir_lock = Mutex.new # Safely changes directory of this process by putting a lock around # it so that it is thread safe. This will yield a block and when the # block exits it changes back to the original directory. # # @param [String] dir Dir to change to temporarily def self.safe_chdir(dir) lock = @@chdir_lock begin @@chdir_lock.synchronize {} rescue ThreadError # If we already hold the lock, just create a new lock so we # definitely don't block and don't get an error. lock = Mutex.new end lock.synchronize do Dir.chdir(dir) do return yield end end end end end end
Version data entries
75 entries across 68 versions & 10 rubygems