summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-02 07:35:14 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-02 07:35:14 +0000
commit373f1770de9a6f3c741832cc86f0bcdc30a14bce (patch)
treed1ea7eb0edc3e07697bf58138619f6c496bcb554
parentcc05e8d97d233e698a5d70e7d5a288a78a942389 (diff)
downloadpuppet-373f1770de9a6f3c741832cc86f0bcdc30a14bce.tar.gz
puppet-373f1770de9a6f3c741832cc86f0bcdc30a14bce.tar.xz
puppet-373f1770de9a6f3c741832cc86f0bcdc30a14bce.zip
Adding sourcematch parameter to file.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2016 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/pfile.rb26
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb1
-rwxr-xr-xtest/types/filesources.rb49
3 files changed, 73 insertions, 3 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 0bc817494..a9254e5ea 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -190,6 +190,14 @@ module Puppet
newvalues(:true, :false)
end
+
+ newparam(:sourcematch) do
+ desc "Whether to copy all valid sources, or just the first one."
+
+ defaultto :first
+
+ newvalues(:first, :all)
+ end
attr_accessor :bucket
@@ -612,6 +620,7 @@ module Puppet
args.each { |var,value|
next if var == :path
next if var == :name
+
# behave idempotently
unless child.should(var) == value
child[var] = value
@@ -829,6 +838,8 @@ module Puppet
ignore = self[:ignore]
+ result = []
+ found = []
@states[:source].should.each do |source|
sourceobj, path = uri2obj(source)
@@ -844,19 +855,30 @@ module Puppet
end
# Now create a new child for every file returned in the list.
- return desc.split("\n").collect { |line|
+ result += desc.split("\n").collect { |line|
file, type = line.split("\t")
next if file == "/" # skip the listing object
name = file.sub(/^\//, '')
+
+ # This makes sure that the first source *always* wins
+ # for conflicting files.
+ next if found.include?(name)
+
args = {:source => source + file}
if type == file
args[:recurse] = nil
end
+ found << name
+
self.newchild(name, false, args)
}.reject {|c| c.nil? }
+
+ if self[:sourcematch] == :first
+ return result
+ end
end
- return []
+ return result
end
# Set the checksum, from another state. There are multiple states that
diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb
index c4ae6e8c3..af3161b9f 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -314,7 +314,6 @@ module Puppet
# end
if @is == sum
- info "Sums are already equal"
return false
end
diff --git a/test/types/filesources.rb b/test/types/filesources.rb
index a3f229a02..49ef73fe2 100755
--- a/test/types/filesources.rb
+++ b/test/types/filesources.rb
@@ -935,6 +935,55 @@ class TestFileSources < Test::Unit::TestCase
assert(FileTest.exists?(newfile), "File did not get created")
assert_equal("yayness\n", File.read(newfile))
end
+
+ def test_sourcematch
+ dest = tempfile()
+ sources = []
+ 2.times { |i|
+ i = i + 1
+ source = tempfile()
+ sources << source
+ file = File.join(source, "file%s" % i)
+ Dir.mkdir(source)
+ File.open(file, "w") { |f| f.print "yay" }
+ }
+ file1 = File.join(dest, "file1")
+ file2 = File.join(dest, "file2")
+ file3 = File.join(dest, "file3")
+
+ # Now make different files with the same name in each source dir
+ sources.each_with_index do |source, i|
+ File.open(File.join(source, "file3"), "w") { |f|
+ f.print i.to_s
+ }
+ end
+
+ obj = Puppet::Type.newfile(:path => dest, :recurse => true,
+ :source => sources)
+
+ assert_equal(:first, obj[:sourcematch], "sourcematch has the wrong default")
+ # First, make sure we default to just copying file1
+ assert_apply(obj)
+
+ assert(FileTest.exists?(file1), "File from source 1 was not copied")
+ assert(! FileTest.exists?(file2), "File from source 2 was copied")
+ assert(FileTest.exists?(file3), "File from source 1 was not copied")
+ assert_equal("0", File.read(file3), "file3 got wrong contents")
+
+ # Now reset sourcematch
+ assert_nothing_raised do
+ obj[:sourcematch] = :all
+ end
+ File.unlink(file1)
+ File.unlink(file3)
+ Puppet.err :yay
+ assert_apply(obj)
+
+ assert(FileTest.exists?(file1), "File from source 1 was not copied")
+ assert(FileTest.exists?(file2), "File from source 2 was copied")
+ assert(FileTest.exists?(file3), "File from source 1 was not copied")
+ assert_equal("0", File.read(file3), "file3 got wrong contents")
+ end
end
# $Id$