diff options
Diffstat (limited to 'lib/puppet/network')
-rw-r--r-- | lib/puppet/network/client/dipper.rb | 85 | ||||
-rwxr-xr-x | lib/puppet/network/handler/filebucket.rb | 139 | ||||
-rw-r--r-- | lib/puppet/network/http/handler.rb | 2 |
3 files changed, 6 insertions, 220 deletions
diff --git a/lib/puppet/network/client/dipper.rb b/lib/puppet/network/client/dipper.rb deleted file mode 100644 index 0e2dc1425..000000000 --- a/lib/puppet/network/client/dipper.rb +++ /dev/null @@ -1,85 +0,0 @@ -# The client class for filebuckets. -class Puppet::Network::Client::Dipper < Puppet::Network::Client - @handler = Puppet::Network::Handler.handler(:filebucket) - @drivername = :Bucket - - attr_accessor :name - - # Create our bucket client - def initialize(hash = {}) - if hash.include?(:Path) - bucket = self.class.handler.new(:Path => hash[:Path]) - hash.delete(:Path) - hash[:Bucket] = bucket - end - - super(hash) - end - - # Back up a file to our bucket - def backup(file) - unless FileTest.exists?(file) - raise(ArgumentError, "File %s does not exist" % file) - end - contents = ::File.read(file) - unless local? - contents = Base64.encode64(contents) - end - begin - return @driver.addfile(contents,file) - rescue => detail - puts detail.backtrace if Puppet[:trace] - raise Puppet::Error, "Could not back up %s: %s" % [file, detail] - end - end - - # Retrieve a file by sum. - def getfile(sum) - if newcontents = @driver.getfile(sum) - unless local? - newcontents = Base64.decode64(newcontents) - end - return newcontents - end - return nil - end - - # Restore the file - def restore(file,sum) - restore = true - if FileTest.exists?(file) - cursum = Digest::MD5.hexdigest(::File.read(file)) - - # if the checksum has changed... - # this might be extra effort - if cursum == sum - restore = false - end - end - - if restore - if newcontents = getfile(sum) - tmp = "" - newsum = Digest::MD5.hexdigest(newcontents) - changed = nil - if FileTest.exists?(file) and ! FileTest.writable?(file) - changed = ::File.stat(file).mode - ::File.chmod(changed | 0200, file) - end - ::File.open(file, ::File::WRONLY|::File::TRUNC|::File::CREAT) { |of| - of.print(newcontents) - } - if changed - ::File.chmod(changed, file) - end - else - Puppet.err "Could not find file with checksum %s" % sum - return nil - end - return newsum - else - return nil - end - end -end - diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb index 4973886f7..bea1c85f5 100755 --- a/lib/puppet/network/handler/filebucket.rb +++ b/lib/puppet/network/handler/filebucket.rb @@ -3,7 +3,6 @@ require 'digest/md5' require 'puppet/external/base64' class Puppet::Network::Handler # :nodoc: - class BucketError < RuntimeError; end # Accept files and store them by md5 sum, returning the md5 sum back # to the client. Alternatively, accept an md5 sum and return the # associated content. @@ -19,53 +18,8 @@ class Puppet::Network::Handler # :nodoc: Puppet::Util.logmethods(self, true) attr_reader :name, :path - # this doesn't work for relative paths - def self.oldpaths(base,md5) - return [ - File.join(base, md5), - File.join(base, md5, "contents"), - File.join(base, md5, "paths") - ] - end - - # this doesn't work for relative paths - def self.paths(base,md5) - dir = File.join(md5[0..7].split("")) - basedir = File.join(base, dir, md5) - return [ - basedir, - File.join(basedir, "contents"), - File.join(basedir, "paths") - ] - end - - # Should we check each file as it comes in to make sure the md5 - # sums match? Defaults to false. - def conflict_check? - @confictchk - end - def initialize(hash) - if hash.include?(:ConflictCheck) - @conflictchk = hash[:ConflictCheck] - hash.delete(:ConflictCheck) - else - @conflictchk = false - end - - if hash.include?(:Path) - @path = hash[:Path] - hash.delete(:Path) - else - if defined? Puppet - @path = Puppet[:bucketdir] - else - @path = File.expand_path("~/.filebucket") - end - end - - Puppet.settings.use(:filebucket) - + @path = hash[:Path] || Puppet[:bucketdir] @name = "Filebucket[#{@path}]" end @@ -75,60 +29,14 @@ class Puppet::Network::Handler # :nodoc: if client contents = Base64.decode64(contents) end - md5 = Digest::MD5.hexdigest(contents) - - bpath, bfile, pathpath = FileBucket.paths(@path,md5) - - # If the file already exists, just return the md5 sum. - if FileTest.exists?(bfile) - # If verification is enabled, then make sure the text matches. - if conflict_check? - verify(contents, md5, bfile) - end - return md5 - end - - # Make the directories if necessary. - unless FileTest.directory?(bpath) - Puppet::Util.withumask(0007) do - FileUtils.mkdir_p(bpath) - end - end - - # Write the file to disk. - msg = "Adding %s(%s)" % [path, md5] - msg += " from #{client}" if client - self.info msg - - # ...then just create the file - Puppet::Util.withumask(0007) do - File.open(bfile, File::WRONLY|File::CREAT, 0440) { |of| - of.print contents - } - end - - # Write the path to the paths file. - add_path(path, pathpath) - - return md5 + bucket = Puppet::FileBucket::File.new(contents) + return bucket.save end # Return the contents associated with a given md5 sum. def getfile(md5, client = nil, clientip = nil) - bpath, bfile, bpaths = FileBucket.paths(@path,md5) - - unless FileTest.exists?(bfile) - # Try the old flat style. - bpath, bfile, bpaths = FileBucket.oldpaths(@path,md5) - unless FileTest.exists?(bfile) - return false - end - end - - contents = nil - File.open(bfile) { |of| - contents = of.read - } + bucket = Puppet::FileBucket::File.find("md5:#{md5}") + contents = bucket.contents if client return Base64.encode64(contents) @@ -137,46 +45,9 @@ class Puppet::Network::Handler # :nodoc: end end - def paths(md5) - self.class(@path, md5) - end - def to_s self.name end - - private - - # Add our path to the paths file if necessary. - def add_path(path, file) - if FileTest.exists?(file) - File.open(file) { |of| - return if of.readlines.collect { |l| l.chomp }.include?(path) - } - end - - # if it's a new file, or if our path isn't in the file yet, add it - File.open(file, File::WRONLY|File::CREAT|File::APPEND) { |of| - of.puts path - } - end - - # If conflict_check is enabled, verify that the passed text is - # the same as the text in our file. - def verify(content, md5, bfile) - curfile = File.read(bfile) - - # If the contents don't match, then we've found a conflict. - # Unlikely, but quite bad. - if curfile != contents - raise(BucketError, - "Got passed new contents for sum %s" % md5, caller) - else - msg = "Got duplicate %s(%s)" % [path, md5] - msg += " from #{client}" if client - self.info msg - end - end end end diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 444fbf7e7..01ca65023 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -165,7 +165,7 @@ module Puppet::Network::HTTP::Handler # LAK:NOTE This has to be here for testing; it's a stub-point so # we keep infinite recursion from happening. def save_object(ind_request, object) - object.save(ind_request.to_hash) + object.save(ind_request) end def get?(request) |