Sha256: 9ad3c4b8675f077d57cdf9af190e25c8d6cf9fe4f8a61d342ea9e37694b70a20
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
require 'fileutils' require 'tempfile' # A support module for testing files. module PuppetSpec::Files # This code exists only to support tests that run as root, pretty much. # Once they have finally been eliminated this can all go... --daniel 2011-04-08 if Puppet.features.posix? then def self.in_tmp(path) path =~ /^\/tmp/ or path =~ /^\/var\/folders/ end elsif Puppet.features.microsoft_windows? def self.in_tmp(path) tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) path =~ /^#{tempdir}/ end else fail "Help! Can't find in_tmp for this platform" end def self.cleanup $global_tempfiles ||= [] while path = $global_tempfiles.pop do fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) begin FileUtils.rm_r path, :secure => true rescue Errno::ENOENT # nothing to do end end end def tmpfile(name) # Generate a temporary file, just for the name... source = Tempfile.new(name) path = source.path source.close! # ...record it for cleanup, $global_tempfiles ||= [] $global_tempfiles << File.expand_path(path) # ...and bam. path end def tmpdir(name) path = tmpfile(name) FileUtils.mkdir_p(path) path end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
puppet-2.7.3 | spec/lib/puppet_spec/files.rb |
puppet-2.7.1 | spec/lib/puppet_spec/files.rb |