summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-11 17:37:40 +0000
committerLuke Kanies <luke@madstop.com>2005-07-11 17:37:40 +0000
commit649d59a24cf03387e58fa1d4a151fcf34e409777 (patch)
tree5f7ca422618bd78d29025aa6947d814f0e4908bf
parentcb95dc753267205bd5b352434bc5518dcd07e70d (diff)
downloadpuppet-649d59a24cf03387e58fa1d4a151fcf34e409777.tar.gz
puppet-649d59a24cf03387e58fa1d4a151fcf34e409777.tar.xz
puppet-649d59a24cf03387e58fa1d4a151fcf34e409777.zip
adding some more tests for recursion plus checksumming, because they are somewhat incompatible for directories
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@353 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xlib/puppet/type/exec.rb5
-rw-r--r--lib/puppet/type/pfile.rb24
-rwxr-xr-xtest/types/tc_exec.rb2
-rw-r--r--test/types/tc_file.rb38
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