diff options
-rwxr-xr-x | lib/puppet/type/exec.rb | 5 | ||||
-rw-r--r-- | lib/puppet/type/pfile.rb | 24 | ||||
-rwxr-xr-x | test/types/tc_exec.rb | 2 | ||||
-rw-r--r-- | test/types/tc_file.rb | 38 |
4 files changed, 61 insertions, 8 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index dec7370eb..2ae401cca 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -161,6 +161,11 @@ module Puppet return self.state(:returns).output end end + + # this might be a very, very bad idea... + def refresh + self.state(:returns).sync + end end end end diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 98c7ff7bd..dbd54404b 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -76,18 +76,30 @@ module Puppet if FileTest.directory?(self.parent[:path]) Puppet.info "Cannot MD5 sum directory %s" % self.parent[:path] + + # because we cannot sum directories, just remove + # the state entirely + self.parent.delete(self.name) + return + else + File.open(self.parent[:path]) { |file| + sum = Digest::MD5.hexdigest(file.read) + } end - File.open(self.parent[:path]) { |file| - sum = Digest::MD5.hexdigest(file.read) - } when "md5lite": if FileTest.directory?(self.parent[:path]) Puppet.info "Cannot MD5 sum directory %s" % self.parent[:path] + + # because we cannot sum directories, just remove + # the state entirely + self.parent.delete(self.name) + return + else + File.open(self.parent[:path]) { |file| + sum = Digest::MD5.hexdigest(file.read(512)) + } end - File.open(self.parent[:path]) { |file| - sum = Digest::MD5.hexdigest(file.read(512)) - } when "timestamp","mtime": sum = File.stat(self.parent[:path]).mtime when "time": diff --git a/test/types/tc_exec.rb b/test/types/tc_exec.rb index 1eada111b..e714caf82 100755 --- a/test/types/tc_exec.rb +++ b/test/types/tc_exec.rb @@ -120,7 +120,7 @@ class TestExec < Test::Unit::TestCase } end - def test_xcwdsettings + def test_cwdsettings command = nil assert_nothing_raised { command = Puppet::Type::Exec.new( diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 00f942a33..05d49b367 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -126,7 +126,7 @@ class TestFile < Test::Unit::TestCase } end - def test_zchecksums + def test_checksums types = %w{md5 md5lite timestamp ctime} files = %w{/tmp/sumtest} types.each { |type| @@ -185,4 +185,40 @@ class TestFile < Test::Unit::TestCase } } end + + def cyclefile(path) + file = nil + assert_nothing_raised { + file = Puppet::Type::PFile.new( + :path => path, + :recurse => true, + :checksum => "md5" + ) + } + assert_nothing_raised { + file.retrieve + } + assert_nothing_raised { + file.sync + } + end + + def test_recursion + path = "/tmp/filerecursetest" + tmpfile = File.join(path,"testing") + system("mkdir -p #{path}") + cyclefile(path) + Puppet::Type::PFile.clear + File.open(tmpfile, File::WRONLY|File::CREAT|File::APPEND) { |of| + of.puts "yayness" + } + cyclefile(path) + Puppet::Type::PFile.clear + File.open(tmpfile, File::WRONLY|File::APPEND) { |of| + of.puts "goodness" + } + cyclefile(path) + Puppet::Type::PFile.clear + system("rm -rf #{path}") + end end |