lib/oats/oats_lock.rb in oats-0.0.2 vs lib/oats/oats_lock.rb in oats-0.0.3
- old
+ new
@@ -1,7 +1,7 @@
# Manages a lock file indicating a OATS session is in process
-require 'win32ole' if RUBY_PLATFORM =~ /mswin32/
+require 'win32ole' if RUBY_PLATFORM =~ /(mswin|mingw)/
module Oats
module OatsLock
@@file_handle = nil
@@is_locked = false
@@ -12,11 +12,11 @@
return false
else
@@file_handle = File.open(in_progress_file, 'w')
my_pid = Process.pid.to_s
@@file_handle.puts my_pid
- if RUBY_PLATFORM !~ /mswin32/ or ENV['TEMP'] =~ /^\/cygdrive/
+ if RUBY_PLATFORM !~ /(mswin|mingw)/ or ENV['TEMP'] =~ /^\/cygdrive/
# Leave file handle open for windows to detect and kill associated java, etc.
# processes using file handles.
@@file_handle.close
@@file_handle = nil
end
@@ -28,11 +28,11 @@
# Returns the locked state after the last check
# verify: true will verify the true state of the lock
def OatsLock.locked?(verify = nil)
return @@is_locked unless verify
@@is_locked = false
- if RUBY_PLATFORM !~ /mswin32/ or ENV['TEMP'] =~ /^\/cygdrive/
+ if RUBY_PLATFORM !~ /(mswin|mingw)/ or ENV['TEMP'] =~ /^\/cygdrive/
if File.exist?(in_progress_file)
pids = IO.readlines(in_progress_file)
ruby_pid = pids.shift
return @@is_locked unless ruby_pid
ps_line = `ps -p #{ruby_pid} `
@@ -138,11 +138,11 @@
end
end
def OatsLock.find_matching_processes(proc_names)
matched = []
- if RUBY_PLATFORM =~ /mswin32/
+ if RUBY_PLATFORM =~ /(mswin|mingw)/
processes = WIN32OLE.connect("winmgmts://").ExecQuery("select * from win32_process")
# for process in processes do
# for property in process.Properties_ do
# puts property.Name
# end
@@ -220,10 +220,10 @@
if @@file_handle # Only for Windows
@@file_handle.close
@@file_handle = nil
@@is_locked = true
else # Doesn't return status properly for non-windows, just resets the lock
- if $oats_execution['agent'].nil? and RUBY_PLATFORM !~ /mswin32/ and File.exist?(in_progress_file)
+ if $oats_execution['agent'].nil? and RUBY_PLATFORM !~ /(mswin|mingw)/ and File.exist?(in_progress_file)
pids = IO.readlines(in_progress_file)
current_pid = pids.shift
pids.each { |pid| OatsLock.kill_pid(pid.chomp) } # Legacy firefox
end
@@is_locked = false
\ No newline at end of file