Module: Bundler::Codegraph::Lock

Defined in:
lib/bundler/codegraph/lock.rb

Overview

Serializes indexing across processes.

codegraph already saturates several cores on its own. Within one bundle install the queue is drained one gem at a time; this advisory file lock covers several bundle install (or a bundle codegraph-index) running side by side.

Constant Summary collapse

LOCK_FILENAME =
'bundler-codegraph.lock'

Class Method Summary collapse

Class Method Details

.path ⇒ String?

Returns nil when the runtime directory cannot be trusted.

Returns:

  • (String, nil) —

    nil when the runtime directory cannot be trusted



19
20
21
22
# File 'lib/bundler/codegraph/lock.rb', line 19

def self.path
  dir = RuntimeDir.path
  dir && File.join(dir, LOCK_FILENAME)
end

.synchronize ⇒ Object

Runs the block while holding the exclusive lock. An untrusted runtime directory, or a filesystem without working advisory locks, degrades to running unserialized rather than failing.

Only opening and locking may fall back: an error raised by the block itself propagates, rather than running the block a second time, unlocked.



30
31
32
33
# File 'lib/bundler/codegraph/lock.rb', line 30

def self.synchronize(&)
  lock_path = path
  lock_path ? with_lock(lock_path, &) : yield
end