1111require_relative '../catalog-util/facts'
1212require_relative '../util/puppetversion'
1313require_relative '../util/scriptrunner'
14+ require_relative '../util/util'
1415
1516module OctocatalogDiff
1617 class Catalog
@@ -69,23 +70,6 @@ def convert_file_resources(dry_run = false)
6970 OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( self , environment )
7071 end
7172
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-
8973 # Private method: Bootstrap a directory
9074 def bootstrap ( logger )
9175 return if @builddir
@@ -99,9 +83,7 @@ def bootstrap(logger)
9983 tmphash [ :basedir ] = @options [ :bootstrapped_dir ]
10084 elsif @options [ :branch ] == '.'
10185 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 ] )
10587 FileUtils . cp_r File . join ( @options [ :basedir ] , '.' ) , tmphash [ :basedir ]
10688
10789 o = @options . reject { |k , _v | k == :branch } . merge ( path : tmphash [ :basedir ] )
@@ -110,9 +92,7 @@ def bootstrap(logger)
11092 tmphash [ :basedir ] = @options [ :basedir ]
11193 end
11294 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 ] )
11696 OctocatalogDiff ::CatalogUtil ::Bootstrap . bootstrap_directory ( @options . merge ( path : checkout_dir ) , logger )
11797 end
11898
@@ -193,7 +173,8 @@ def exec_puppet(logger)
193173 # Set up the ScriptRunner
194174 scriptrunner = OctocatalogDiff ::Util ::ScriptRunner . new (
195175 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 ]
197178 )
198179
199180 begin
0 commit comments