summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-24 21:16:20 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-24 21:16:20 +0000
commit52df47e489d390be9b466da3ef16c2379b9dddba (patch)
treed5006c428e3fae2646a6f60b5e7333dc2da31e87 /lib
parentdef15e3de0a488f2f9d75eeb43d04381742609f6 (diff)
downloadpuppet-52df47e489d390be9b466da3ef16c2379b9dddba.tar.gz
puppet-52df47e489d390be9b466da3ef16c2379b9dddba.tar.xz
puppet-52df47e489d390be9b466da3ef16c2379b9dddba.zip
Finalizing the filebucket client, with test code.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2348 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/network/client/dipper.rb20
-rwxr-xr-xlib/puppet/network/handler/filebucket.rb2
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/puppet/network/client/dipper.rb b/lib/puppet/network/client/dipper.rb
index 2084e09f6..5ddb67db1 100644
--- a/lib/puppet/network/client/dipper.rb
+++ b/lib/puppet/network/client/dipper.rb
@@ -28,6 +28,17 @@ class Puppet::Network::Client::Dipper < Puppet::Network::Client
return @driver.addfile(contents,file)
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
@@ -42,18 +53,15 @@ class Puppet::Network::Client::Dipper < Puppet::Network::Client
end
if restore
- if newcontents = @driver.getfile(sum)
- unless local?
- newcontents = Base64.decode64(newcontents)
- end
+ if newcontents = getfile(sum)
tmp = ""
newsum = Digest::MD5.hexdigest(newcontents)
changed = nil
- unless FileTest.writable?(file)
+ 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) { |of|
+ ::File.open(file, ::File::WRONLY|::File::TRUNC|::File::CREAT) { |of|
of.print(newcontents)
}
if changed
diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb
index f0d389aea..705a4eee9 100755
--- a/lib/puppet/network/handler/filebucket.rb
+++ b/lib/puppet/network/handler/filebucket.rb
@@ -28,7 +28,7 @@ class Puppet::Network::Handler # :nodoc:
# this doesn't work for relative paths
def self.paths(base,md5)
dir = File.join(md5[0..7].split(""))
- basedir = File.join(base, dir)
+ basedir = File.join(base, dir, md5)
return [
basedir,
File.join(basedir, "contents"),