11
11
require_relative '../catalog-util/facts'
12
12
require_relative '../util/puppetversion'
13
13
require_relative '../util/scriptrunner'
14
+ require_relative '../util/util'
14
15
15
16
module OctocatalogDiff
16
17
class Catalog
@@ -69,23 +70,6 @@ def convert_file_resources(dry_run = false)
69
70
OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( self , environment )
70
71
end
71
72
72
- private
73
-
74
- # Private method: Clean up a checkout directory, if it exists
75
- def cleanup_checkout_dir ( checkout_dir , logger )
76
- return unless File . directory? ( checkout_dir )
77
- logger . debug ( "Cleaning up temporary directory #{ checkout_dir } " )
78
- # Sometimes this seems to break when handling the recursive removal when running under
79
- # a parallel environment. Trap and ignore the errors here if we don't care about them.
80
- begin
81
- FileUtils . remove_entry_secure checkout_dir
82
- # :nocov:
83
- rescue Errno ::ENOTEMPTY , Errno ::ENOENT => exc
84
- logger . debug "cleanup_checkout_dir(#{ checkout_dir } ) logged #{ exc . class } - this can be ignored"
85
- # :nocov:
86
- end
87
- end
88
-
89
73
# Private method: Bootstrap a directory
90
74
def bootstrap ( logger )
91
75
return if @builddir
@@ -99,9 +83,7 @@ def bootstrap(logger)
99
83
tmphash [ :basedir ] = @options [ :bootstrapped_dir ]
100
84
elsif @options [ :branch ] == '.'
101
85
if @options [ :bootstrap_current ]
102
- tmphash [ :basedir ] = Dir . mktmpdir ( 'ocd-bootstrap-basedir-' )
103
- at_exit { cleanup_checkout_dir ( tmphash [ :basedir ] , logger ) }
104
-
86
+ tmphash [ :basedir ] = OctocatalogDiff ::Util ::Util . temp_dir ( 'ocd-bootstrap-basedir-' , @options [ :existing_tempdir ] )
105
87
FileUtils . cp_r File . join ( @options [ :basedir ] , '.' ) , tmphash [ :basedir ]
106
88
107
89
o = @options . reject { |k , _v | k == :branch } . merge ( path : tmphash [ :basedir ] )
@@ -110,9 +92,7 @@ def bootstrap(logger)
110
92
tmphash [ :basedir ] = @options [ :basedir ]
111
93
end
112
94
else
113
- checkout_dir = Dir . mktmpdir ( 'ocd-bootstrap-checkout-' )
114
- at_exit { cleanup_checkout_dir ( checkout_dir , logger ) }
115
- tmphash [ :basedir ] = checkout_dir
95
+ tmphash [ :basedir ] = OctocatalogDiff ::Util ::Util . temp_dir ( 'ocd-bootstrap-checkout-' , @options [ :existing_tempdir ] )
116
96
OctocatalogDiff ::CatalogUtil ::Bootstrap . bootstrap_directory ( @options . merge ( path : checkout_dir ) , logger )
117
97
end
118
98
@@ -193,7 +173,8 @@ def exec_puppet(logger)
193
173
# Set up the ScriptRunner
194
174
scriptrunner = OctocatalogDiff ::Util ::ScriptRunner . new (
195
175
default_script : 'puppet/puppet.sh' ,
196
- override_script_path : @options [ :override_script_path ]
176
+ override_script_path : @options [ :override_script_path ] ,
177
+ existing_tempdir : @options [ :existing_tempdir ]
197
178
)
198
179
199
180
begin
0 commit comments