From: <jh...@us...> - 2012-04-27 01:59:32
|
Revision: 329 http://etch.svn.sourceforge.net/etch/?rev=329&view=rev Author: jheiss Date: 2012-04-27 01:59:26 +0000 (Fri, 27 Apr 2012) Log Message: ----------- Store @results as a hash so that we only capture the last result for each individual file. This eliminates a bunch of empty and misleading results for files from handling need_sum or need_orig requests. We only want to capture the last result where the contents of the file are handled. If ruby >= 1.9 then specify encoding options to the pipes used for output capturing. Otherwise we may end up capturing non-UTF-8 output and sending it to the server as UTF-8, which causes the server to error out. Minor cleanup in lock_file to eliminate a warning about an unused variable. Modified Paths: -------------- trunk/client/lib/etch/client.rb Modified: trunk/client/lib/etch/client.rb =================================================================== --- trunk/client/lib/etch/client.rb 2012-04-27 01:50:53 UTC (rev 328) +++ trunk/client/lib/etch/client.rb 2012-04-27 01:59:26 UTC (rev 329) @@ -204,7 +204,7 @@ @already_processed = {} @exec_already_processed = {} @exec_once_per_run = {} - @results = [] + @results = {} # See start/stop_output_capture for these @output_pipes = [] @@ -521,11 +521,11 @@ rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" if @detailed_results.include?('SERVER') - @results.each do |result| + @results.each do |file, result| # Strangely enough this works. Even though the key is not unique to # each result the Rails parameter parsing code keeps track of keys it # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][file]=#{CGI.escape(file)}" rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" rails_results << "results[][message]=#{CGI.escape(result['message'])}" end @@ -563,8 +563,8 @@ file.puts "Message:\n#{message}\n" end # Then the detailed results - @results.each do |result| - file.puts "File #{result['file']}, result #{result['success']}:\n" + @results.each do |resultfile, result| + file.puts "File #{resultfile}, result #{result['success']}:\n" file.puts result['message'] end end @@ -621,7 +621,6 @@ # Prep the results capturing for this file result = {} - result['file'] = file result['success'] = true result['message'] = '' @@ -1504,7 +1503,7 @@ end result['message'] << output if save_results - @results << result + @results[file] = result end if exception @@ -1542,7 +1541,6 @@ # Prep the results capturing for this command result = {} - result['file'] = commandname result['success'] = true result['message'] = '' @@ -1637,7 +1635,7 @@ end result['message'] << output if save_results - @results << result + @results[commandname] = result end if exception @@ -2384,9 +2382,9 @@ # Make 30 attempts (1s sleep after each attempt) 30.times do |i| begin - fd = IO::sysopen(lockpath, Fcntl::O_WRONLY|Fcntl::O_CREAT|Fcntl::O_EXCL) + fd = File.sysopen(lockpath, Fcntl::O_WRONLY|Fcntl::O_CREAT|Fcntl::O_EXCL) puts "Lock acquired for #{file}" if (@debug) - f = IO.open(fd) { |lockfile| lockfile.puts $$ } + File.open(fd) { |lockfile| lockfile.puts $$ } @locked_files[file] = true return rescue Errno::EEXIST @@ -2459,8 +2457,14 @@ # to the pipe. The child gathers up anything sent over the pipe and # when we close the pipe later it sends the captured output back to us # over a second pipe. - pread, pwrite = IO.pipe - oread, owrite = IO.pipe + pread = pwrite = oread = owrite = nil + if RUBY_VERSION.split('.')[0..1].join('.').to_f >= 1.9 + pread, pwrite = IO.pipe(Encoding.default_external, 'UTF-8', :invalid => :replace, :undef => :replace) + oread, owrite = IO.pipe(Encoding.default_external, 'UTF-8', :invalid => :replace, :undef => :replace) + else + pread, pwrite = IO.pipe + oread, owrite = IO.pipe + end if fork # Parent pread.close This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |