From 9d0d99872171eb9e310aeccf2349f9f6559fb760 Mon Sep 17 00:00:00 2001 From: Seamus Abshere Date: Wed, 30 Mar 2011 13:09:19 -0500 Subject: [PATCH] handle forking, which previously led to the same random numbers (and therefore tmpdirs) being generated --- lib/remote_table/executor.rb | 1 + lib/remote_table/format/fixed_width.rb | 1 + lib/remote_table/properties.rb | 1 + lib/remote_table/version.rb | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/remote_table/executor.rb b/lib/remote_table/executor.rb index c31904e..0efb2aa 100644 --- a/lib/remote_table/executor.rb +++ b/lib/remote_table/executor.rb @@ -7,6 +7,7 @@ class RemoteTable class Executor include ::Singleton def bang(path, cmd) + srand # in case this was forked by resque tmp_path = "#{path}.bang.#{rand}" backtick_with_reporting "cat #{::Escape.shell_single_word path} | #{cmd} > #{::Escape.shell_single_word tmp_path}" ::FileUtils.mv tmp_path, path diff --git a/lib/remote_table/format/fixed_width.rb b/lib/remote_table/format/fixed_width.rb index 67362b5..6775dd0 100644 --- a/lib/remote_table/format/fixed_width.rb +++ b/lib/remote_table/format/fixed_width.rb @@ -25,6 +25,7 @@ def definition ::Slither.send :definition, t.properties.schema_name elsif t.properties.schema.is_a?(::Array) everything = lambda { |_| true } + srand # in case this was forked by resque ::Slither.define(rand.to_s) do |d| d.rows do |row| row.trap(&everything) diff --git a/lib/remote_table/properties.rb b/lib/remote_table/properties.rb index 5f0aedc..444208f 100644 --- a/lib/remote_table/properties.rb +++ b/lib/remote_table/properties.rb @@ -212,6 +212,7 @@ def format def staging_dir_path #:nodoc: return @staging_dir_path if @staging_dir_path.is_a?(::String) + srand # in case this was forked by resque @staging_dir_path = ::File.join ::Dir.tmpdir, 'remote_table_gem', rand.to_s ::FileUtils.mkdir_p @staging_dir_path @staging_dir_path diff --git a/lib/remote_table/version.rb b/lib/remote_table/version.rb index 4de2e2b..dd3529d 100644 --- a/lib/remote_table/version.rb +++ b/lib/remote_table/version.rb @@ -1,3 +1,3 @@ class RemoteTable - VERSION = "1.1.3" + VERSION = "1.1.4" end