time0 = Time.new.strftime("%Y-%m-%d %X")
File.open(path, "w") do |fh|
+ fh.flock(File::LOCK_EX)
fh.puts [time0, ARGV.join(" ")].join(";")
end
end
status = ""
File.open(path, "r") do |fh|
+ fh.flock(File::LOCK_SH)
status = fh.read.chomp
end
status = "#{status};#{tmpdir_path}\n"
File.open(path, "w") do |fh|
+ fh.flock(File::LOCK_EX)
fh << status
end
end
# and return this or nil if not found.
def get_tmpdir
File.open(path, "r") do |fh|
+ fh.flock(File::LOCK_SH)
tmpdir_path = fh.read.chomp.split(";").last
return tmpdir_path if File.directory?(tmpdir_path)
end
user = ENV["USER"]
script = File.basename($0)
- stream = File.open(path)
- time0, args = stream.first.split(";")
- stream.close
+ time0 = nil
+ args = nil
+
+ File.open(path, "r") do |fh|
+ fh.flock(File::LOCK_SH)
+ time0, args = fh.first.split(";")
+ end
elap = time_diff(time0, time1)
command = [script, args].join(" ")
log_file = File.join(ENV["BP_LOG"], "biopieces.log")
- File.open(log_file, "a") { |file| file.puts [time0, time1, elap, user, exit_status, command].join("\t") }
+ File.open(log_file, "a") do |fh|
+ fh.flock(File::LOCK_EX)
+ fh.puts [time0, time1, elap, user, exit_status, command].join("\t")
+ end
end
# Delete status file.