~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/lib/puppet_spec/files.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
# A support module for testing files.
5
5
module PuppetSpec::Files
 
6
  # This code exists only to support tests that run as root, pretty much.
 
7
  # Once they have finally been eliminated this can all go... --daniel 2011-04-08
 
8
  if Puppet.features.posix? then
 
9
    def self.in_tmp(path)
 
10
      path =~ /^\/tmp/ or path =~ /^\/var\/folders/
 
11
    end
 
12
  elsif Puppet.features.microsoft_windows?
 
13
    def self.in_tmp(path)
 
14
      tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp"))
 
15
      path =~ /^#{tempdir}/
 
16
    end
 
17
  else
 
18
    fail "Help! Can't find in_tmp for this platform"
 
19
  end
 
20
 
 
21
  def self.cleanup
 
22
    $global_tempfiles ||= []
 
23
    while path = $global_tempfiles.pop do
 
24
      fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
 
25
 
 
26
      begin
 
27
        FileUtils.rm_r path, :secure => true
 
28
      rescue Errno::ENOENT
 
29
        # nothing to do
 
30
      end
 
31
    end
 
32
  end
 
33
 
6
34
  def tmpfile(name)
 
35
    # Generate a temporary file, just for the name...
7
36
    source = Tempfile.new(name)
8
37
    path = source.path
9
38
    source.close!
10
 
    $tmpfiles ||= []
11
 
    $tmpfiles << path
 
39
 
 
40
    # ...record it for cleanup,
 
41
    $global_tempfiles ||= []
 
42
    $global_tempfiles << File.expand_path(path)
 
43
 
 
44
    # ...and bam.
12
45
    path
13
46
  end
14
47
 
15
48
  def tmpdir(name)
16
 
    file = tmpfile(name)
17
 
    FileUtils.mkdir_p(file)
18
 
    file
 
49
    path = tmpfile(name)
 
50
    FileUtils.mkdir_p(path)
 
51
    path
19
52
  end
20
53
end