summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-08-02 10:46:53 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-08-19 13:52:58 -0700
commit4a6d61717eb54a0cefff87bf67ae62df1e3b4317 (patch)
treeee91cde7a7c1e510430b44a1a9c36eb8dfd80b4a
parent8c889187a4699f8b797e7a960343558fd2cb8e34 (diff)
downloadpuppet-4a6d61717eb54a0cefff87bf67ae62df1e3b4317.tar.gz
puppet-4a6d61717eb54a0cefff87bf67ae62df1e3b4317.tar.xz
puppet-4a6d61717eb54a0cefff87bf67ae62df1e3b4317.zip
Consolidate test logic determining if a registered file is in the temp directory
Previously, we were always using string comparisons, and hard-coded paths to temp locations on non-Windows platforms. This was problematic for a few reasons. We had to maintain a list of temp locations for the various platforms, and the string comparisons were unreliable on Windows, since paths have two string representations (the "short" name containing a ~ followed by a number, and the "full" name). By getting the current temp location using Dir.tempdir (the same mechanism our temp creation code uses), we no longer need to maintain the list of temp locations. Also, rather than doing string comparisons on file paths, we can use a combination of Pathname#ascend, and File.identical? to determine if the path registered as a temp file for deletion was actually created in the temp location. With this refactoring, the same code now works for both Windows, and non-Windows platforms. Reviewed-by: Nick Lewis <nick@puppetlabs.com> (cherry picked from commit 3aec02ba0e4bda8ba4e9fffbc6defaae4e4e2ba1)
-rwxr-xr-xspec/lib/puppet_spec/files.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 9e75d3142..725bf2af9 100755
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -1,21 +1,19 @@
require 'fileutils'
require 'tempfile'
+require 'pathname'
# 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}/
+ def self.in_tmp(path)
+ tempdir = Dir.tmpdir
+
+ Pathname.new(path).ascend do |dir|
+ return true if File.identical?(tempdir, dir)
end
- else
- fail "Help! Can't find in_tmp for this platform"
+
+ false
end
def self.cleanup