Sha256: 70374aa85c2d6e01cbff3f73cb666b3e1580f577d376f476e693556cc5c7edf8

Contents?: true

Size: 1.25 KB

Versions: 165

Compression:

Stored size: 1.25 KB

Contents

require 'fileutils'
require 'tempfile'
require 'pathname'

# A support module for testing files.
module PuppetlabsSpec::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
  def self.in_tmp(path)
    tempdir = Dir.tmpdir

    Pathname.new(path).ascend do |dir|
      return true if File.identical?(tempdir, dir)
    end

    false
  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 make_absolute(path)
    path = File.expand_path(path)
    path[0] = 'c' if Puppet.features.microsoft_windows?
    path
  end

  def tmpfilename(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 = tmpfilename(name)
    FileUtils.mkdir_p(path)
    path
  end
end

Version data entries

165 entries across 165 versions & 4 rubygems

Version Path
facter-2.5.7 spec/puppetlabs_spec/files.rb
facter-2.5.7-x86-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.7-x64-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.7-universal-darwin spec/puppetlabs_spec/files.rb
facter-2.5.6-x86-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.6-x64-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.6-universal-darwin spec/puppetlabs_spec/files.rb
facter-2.5.6 spec/puppetlabs_spec/files.rb
facter-2.5.5-x86-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.5-x64-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.5-universal-darwin spec/puppetlabs_spec/files.rb
facter-2.5.5 spec/puppetlabs_spec/files.rb
facter-2.5.4-x86-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.4-x64-mingw32 spec/puppetlabs_spec/files.rb
facter-2.5.4-universal-darwin spec/puppetlabs_spec/files.rb
facter-2.5.4 spec/puppetlabs_spec/files.rb
puppetlabs_spec_helper-2.8.0 lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
puppetlabs_spec_helper-2.7.0 lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
puppetlabs_spec_helper-2.6.2 lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb
puppetlabs_spec_helper-2.6.1 lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb