Skip to content

Commit 2c6d7e0

Browse files
committed
Use environment within forked process to pass temporary directory
1 parent 356226c commit 2c6d7e0

File tree

5 files changed

+6
-43
lines changed

5 files changed

+6
-43
lines changed

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BuildDir
3939
# @param options [Hash] Options for class; see above description
4040
def initialize(options = {}, logger = nil)
4141
@options = options.dup
42-
@tempdir = OctocatalogDiff::Util::Util.temp_dir('ocd-builddir-', options[:existing_tempdir])
42+
@tempdir = OctocatalogDiff::Util::Util.temp_dir('ocd-builddir-')
4343
@factdir = nil
4444
@enc = nil
4545
@fact_file = nil

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def bootstrap(logger)
8383
tmphash[:basedir] = @options[:bootstrapped_dir]
8484
elsif @options[:branch] == '.'
8585
if @options[:bootstrap_current]
86-
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-basedir-', @options[:existing_tempdir])
86+
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-basedir-')
8787
FileUtils.cp_r File.join(@options[:basedir], '.'), tmphash[:basedir]
8888

8989
o = @options.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
@@ -92,7 +92,7 @@ def bootstrap(logger)
9292
tmphash[:basedir] = @options[:basedir]
9393
end
9494
else
95-
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-checkout-', @options[:existing_tempdir])
95+
tmphash[:basedir] = OctocatalogDiff::Util::Util.temp_dir('ocd-bootstrap-checkout-')
9696
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(@options.merge(path: checkout_dir), logger)
9797
end
9898

@@ -173,8 +173,7 @@ def exec_puppet(logger)
173173
# Set up the ScriptRunner
174174
scriptrunner = OctocatalogDiff::Util::ScriptRunner.new(
175175
default_script: 'puppet/puppet.sh',
176-
override_script_path: @options[:override_script_path],
177-
existing_tempdir: @options[:existing_tempdir]
176+
override_script_path: @options[:override_script_path]
178177
)
179178

180179
begin

lib/octocatalog-diff/util/parallel.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def self.run_tasks_parallel(result, task_array, logger)
114114
# simplecov doesn't see this because it's forked
115115
# :nocov:
116116
this_pid = fork do
117+
ENV['OCTOCATALOG_DIFF_TEMPDIR'] = ipc_tempdir
117118
task_result = execute_task(task, logger)
118119
File.open(File.join(ipc_tempdir, "#{Process.pid}.dat"), 'w') { |f| f.write Marshal.dump(task_result) }
119120
Kernel.exit! 0 # Kernel.exit! avoids at_exit from parents being triggered by children exiting

lib/octocatalog-diff/util/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def self.deep_dup(object)
5555
# basedir - A String with the directory in which to make the tempdir
5656
#
5757
# Returns the full path to the temporary directory.
58-
def self.temp_dir(prefix = 'ocd-', basedir = nil)
58+
def self.temp_dir(prefix = 'ocd-', basedir = ENV['OCTOCATALOG_DIFF_TEMPDIR'])
5959
# If the base directory is specified, make sure it exists, and then create the
6060
# temporary directory within it.
6161
if basedir

spec/octocatalog-diff/tests/util/scriptrunner_spec.rb

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,43 +57,6 @@
5757
end
5858
end
5959

60-
describe '#temp_script' do
61-
context 'when running under --parallel' do
62-
before(:each) do
63-
@base_tempdir = Dir.mktmpdir('ocd-tempdir')
64-
end
65-
66-
after(:each) do
67-
OctocatalogDiff::Spec.clean_up_tmpdir(@base_tempdir)
68-
end
69-
70-
it 'should create a temporary directory within the existing tempdir' do
71-
opts = {
72-
default_script: 'env/env.sh',
73-
existing_tempdir: @base_tempdir
74-
}
75-
subject = described_class.new(opts)
76-
script = subject.send(:temp_script, subject.script_src)
77-
78-
regex = Regexp.new('\\A' + Regexp.escape(@base_tempdir) + '/ocd-scriptrunner[^/]+/env.sh\\z')
79-
expect(script).to match(regex)
80-
end
81-
end
82-
83-
context 'when not running under --parallel' do
84-
it 'should create a new temporary directory and clean it up at_exit' do
85-
opts = {
86-
default_script: 'env/env.sh'
87-
}
88-
subject = described_class.new(opts)
89-
script = subject.send(:temp_script, subject.script_src)
90-
91-
regex = Regexp.new('/ocd-scriptrunner[^/]+/env.sh\\z')
92-
expect(script).to match(regex)
93-
end
94-
end
95-
end
96-
9760
describe '#run' do
9861
before(:each) do
9962
@logger, @logger_str = OctocatalogDiff::Spec.setup_logger

0 commit comments

Comments
 (0)