Skip to content

Commit 94d0ffd

Browse files
committed
Take turns on the shared advisory database in bin/bundler-audit
Every checkout on a machine shares ~/.local/share/ruby-advisory-db, and "bundler-audit check --update" git-pulls into it. When two bin/ci runs reach Security: Gem audit together, git refuses the second pull and that run fails. Hold an exclusive flock on a lock file beside the database for the whole check, so concurrent runs wait their turn instead.
1 parent b09bad3 commit 94d0ffd

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎bin/bundler-audit‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/usr/bin/env ruby
22
require_relative "../config/boot"
33
require "bundler/audit/cli"
4+
require "fileutils"
45

56
ARGV.concat %w[ --config config/bundler-audit.yml ] if ARGV.empty? || ARGV.include?("check")
6-
Bundler::Audit::CLI.start
7+
8+
# Every checkout on a machine shares one advisory database, and git refuses a
9+
# second pull into it while one is under way, failing whichever bin/ci run came
10+
# second. Take turns.
11+
lock = "#{Bundler::Audit::Database.path}.lock"
12+
FileUtils.mkdir_p File.dirname(lock)
13+
File.open(lock, File::RDWR | File::CREAT) do |file|
14+
file.flock File::LOCK_EX
15+
Bundler::Audit::CLI.start
16+
end

0 commit comments

Comments
 (0)