summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-27 18:20:37 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-12-27 18:20:37 +0000
commit92ff7121ec656b36815b14533fba5e92c165eb08 (patch)
tree3bf068822a983aba185db9366ccbba846005e594
parent8ff7e0c75eda0291a169074c67fa0a90db9c4e7b (diff)
downloadpuppet-92ff7121ec656b36815b14533fba5e92c165eb08.tar.gz
puppet-92ff7121ec656b36815b14533fba5e92c165eb08.tar.xz
puppet-92ff7121ec656b36815b14533fba5e92c165eb08.zip
Fixing #365. I am not sure what the problem was in previous versions, because the new graphing stuff changed the solution to this problem, but it all works now.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1972 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/client/dipper.rb12
-rwxr-xr-xlib/puppet/server/filebucket.rb14
-rw-r--r--lib/puppet/type/pfile.rb7
-rwxr-xr-xtest/types/file.rb57
4 files changed, 81 insertions, 9 deletions
diff --git a/lib/puppet/client/dipper.rb b/lib/puppet/client/dipper.rb
index a9de76e6f..a3a69ffa4 100644
--- a/lib/puppet/client/dipper.rb
+++ b/lib/puppet/client/dipper.rb
@@ -26,7 +26,11 @@ module Puppet
unless FileTest.exists?(file)
raise(BucketError, "File %s does not exist" % file)
end
- return @driver.addfile(Base64.encode64(File.read(file)),file)
+ contents = File.read(file)
+ unless local?
+ contents = Base64.encode64(contents)
+ end
+ return @driver.addfile(contents,file)
end
# Restore the file
@@ -44,8 +48,10 @@ module Puppet
if restore
#puts "Restoring %s" % file
- if tmp = @driver.getfile(sum)
- newcontents = Base64.decode64(tmp)
+ if newcontents = @driver.getfile(sum)
+ unless local?
+ newcontents = Base64.decode64(newcontents)
+ end
tmp = ""
newsum = Digest::MD5.hexdigest(newcontents)
changed = nil
diff --git a/lib/puppet/server/filebucket.rb b/lib/puppet/server/filebucket.rb
index 3fd4a8f5f..fa86e970b 100755
--- a/lib/puppet/server/filebucket.rb
+++ b/lib/puppet/server/filebucket.rb
@@ -64,8 +64,10 @@ class Server
end
# accept a file from a client
- def addfile(string,path, client = nil, clientip = nil)
- contents = Base64.decode64(string)
+ def addfile(contents, path, client = nil, clientip = nil)
+ if client
+ contents = Base64.decode64(contents)
+ end
md5 = Digest::MD5.hexdigest(contents)
bpath, bfile, pathpath = FileBucket.paths(@path,md5)
@@ -141,8 +143,12 @@ class Server
File.open(bfile) { |of|
contents = of.read
}
-
- return Base64.encode64(contents)
+
+ if client
+ return Base64.encode64(contents)
+ else
+ return contents
+ end
end
def to_s
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 0bb67d5bb..c3206414e 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -77,8 +77,11 @@ module Puppet
# We can't depend on looking this up right now,
# we have to do it after all of the objects
# have been instantiated.
- @bucket = value
- value
+ if bucketobj = Puppet::Type.type(:filebucket)[value]
+ @bucket = bucketobj.bucket
+ else
+ @bucket = value
+ end
else
self.fail "Invalid backup type %s" %
value.inspect
diff --git a/test/types/file.rb b/test/types/file.rb
index ef405638d..6d9cc7285 100755
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -1810,6 +1810,63 @@ class TestFile < Test::Unit::TestCase
file[:replace] = :no
assert_equal(:false, file[:replace], ":replace did not alias :false to :no")
end
+
+ # #365
+ def test_recursive_filebuckets
+ source = tempfile()
+ dest = tempfile()
+ s1 = File.join(source, "1")
+ sdir = File.join(source, "dir")
+ s2 = File.join(sdir, "2")
+ Dir.mkdir(source)
+ Dir.mkdir(sdir)
+ [s1, s2].each { |file| File.open(file, "w") { |f| f.puts "yay: %s" % File.basename(file) } }
+
+ sums = {}
+ [s1, s2].each do |f|
+ sums[File.basename(f)] = Digest::MD5.hexdigest(File.read(f))
+ end
+
+ dfiles = [File.join(dest, "1"), File.join(dest, "dir", "2")]
+
+ bpath = tempfile
+ bucket = Puppet::Type.type(:filebucket).create :name => "rtest", :path => bpath
+ dipper = bucket.bucket
+ dipper = Puppet::Server::FileBucket.new(
+ :Path => bpath
+ )
+ assert(dipper, "did not receive bucket client")
+ file = Puppet::Type.newfile :path => dest, :source => source, :recurse => true, :backup => "rtest"
+
+ assert_apply(file)
+ dfiles.each do |f|
+ assert(FileTest.exists?(f), "destfile %s was not created" % f)
+ end
+
+ # Now modify the source files to make sure things get backed up correctly
+ [s1, s2].each { |sf| File.open(sf, "w") { |f| f.puts "boo: %s" % File.basename(sf) } }
+
+ assert_apply(file)
+ dfiles.each do |f|
+ assert_equal("boo: %s\n" % File.basename(f), File.read(f), "file was not copied correctly")
+ end
+
+ # Make sure we didn't just copy the files over to backup locations
+ dfiles.each do |f|
+ assert(! FileTest.exists?(f + "rtest"), "file %s was copied for backup instead of bucketed" % File.basename(f))
+ end
+
+ # Now make sure we can get the source sums from the bucket
+ sums.each do |f, sum|
+ result = nil
+ assert_nothing_raised do
+ result = dipper.getfile(sum)
+ end
+ assert(result, "file %s was not backed to filebucket" % f)
+ assert_equal("yay: %s\n" % f, result, "file backup was not correct")
+ end
+
+ end
end
# $Id$