@@ -319,29 +319,36 @@ def disable_msys_apps_per_ps1
319
319
end . join ( ";" )
320
320
end
321
321
322
+ @@pacman_lock = Mutex . new
323
+ private def with_pacman_lock ( &block )
324
+ @@pacman_lock . synchronize ( &block )
325
+ end
326
+
322
327
def install_packages ( packages , verbose : false )
323
328
return if packages . empty?
324
329
325
330
with_msys_apps_enabled do
326
- # Find packages that are already installed
327
- skips , installs = packages . partition do |package |
328
- IO . popen ( [ "pacman" , "-Q" , package ] , err : :out , &:read )
329
- $?. success?
330
- end
331
+ with_pacman_lock do
332
+ # Find packages that are already installed
333
+ skips , installs = packages . partition do |package |
334
+ IO . popen ( [ "pacman" , "-Q" , package ] , err : :out , &:read )
335
+ $?. success?
336
+ end
331
337
332
- Gem . ui . say ( "Using msys2 packages: #{ skips . join ( " " ) } " ) if verbose && skips . any?
338
+ Gem . ui . say ( "Using msys2 packages: #{ skips . join ( " " ) } " ) if verbose && skips . any?
333
339
334
- # Install required packages
335
- if installs . any?
336
- Gem . ui . say ( "Installing required msys2 packages: #{ installs . join ( " " ) } " ) if verbose
340
+ # Install required packages
341
+ if installs . any?
342
+ Gem . ui . say ( "Installing required msys2 packages: #{ installs . join ( " " ) } " ) if verbose
337
343
338
- args = [ "pacman" , "-S" , "--needed" , "--noconfirm" , *installs ]
339
- Gem . ui . say ( "> #{ args . join ( " " ) } " ) if verbose ==1
344
+ args = [ "pacman" , "-S" , "--needed" , "--noconfirm" , *installs ]
345
+ Gem . ui . say ( "> #{ args . join ( " " ) } " ) if verbose ==1
340
346
341
- res = IO . popen ( args , &:read )
342
- raise CommandError , "pacman failed with the following output:\n #{ res } " if !$? || $?. exitstatus != 0
347
+ res = IO . popen ( args , &:read )
348
+ raise CommandError , "pacman failed with the following output:\n #{ res } " if !$? || $?. exitstatus != 0
343
349
344
- Gem . ui . say ( res ) if verbose ==1
350
+ Gem . ui . say ( res ) if verbose ==1
351
+ end
345
352
end
346
353
end
347
354
end
0 commit comments