@@ -73,26 +73,34 @@ def install_test_deps
7373 def install_vendored_compact_index
7474 target_root = Path . tmp_root . join ( "compact_index" )
7575 require "fileutils"
76+ FileUtils . mkdir_p ( Path . tmp_root )
7677
77- if ENV [ "COMPACT_INDEX_REF" ]
78- FileUtils . rm_rf ( target_root )
79- elsif File . exist? ( target_root . join ( "lib/compact_index.rb" ) )
80- return
81- end
82-
83- require "open-uri"
84- ref = ENV [ "COMPACT_INDEX_REF" ] || "7c68a7b39761c61a66f9299f85b889ec39afc02c"
85- %w[
78+ files = %w[
8679 lib/compact_index.rb
8780 lib/compact_index/dependency.rb
8881 lib/compact_index/gem.rb
8982 lib/compact_index/gem_version.rb
9083 lib/compact_index/versions_file.rb
91- ] . each do |path |
92- url = "https://raw.githubusercontent.com/rubygems/rubygems.org/#{ ref } /#{ path } "
93- target = target_root . join ( path )
94- FileUtils . mkdir_p ( File . dirname ( target ) )
95- File . write ( target , URI . parse ( url ) . open ( &:read ) )
84+ ]
85+
86+ # Serialize installs so parallel test setups don't race on the same
87+ # vendor tree, and only skip the download when every file is present so
88+ # an interrupted run can't leave a partial copy behind.
89+ File . open ( Path . tmp_root . join ( "compact_index.lock" ) , File ::CREAT | File ::RDWR ) do |lock |
90+ lock . flock ( File ::LOCK_EX )
91+
92+ FileUtils . rm_rf ( target_root ) if ENV [ "COMPACT_INDEX_REF" ]
93+
94+ next if files . all? { |path | File . exist? ( target_root . join ( path ) ) }
95+
96+ require "open-uri"
97+ ref = ENV [ "COMPACT_INDEX_REF" ] || "7c68a7b39761c61a66f9299f85b889ec39afc02c"
98+ files . each do |path |
99+ url = "https://raw.githubusercontent.com/rubygems/rubygems.org/#{ ref } /#{ path } "
100+ target = target_root . join ( path )
101+ FileUtils . mkdir_p ( File . dirname ( target ) )
102+ File . write ( target , URI . parse ( url ) . open ( &:read ) )
103+ end
96104 end
97105 end
98106
0 commit comments