From a002231f45339da9b152162c2f48126d95e2e246 Mon Sep 17 00:00:00 2001
From: Jesse Wolfe <jes5199@gmail.com>
Date: Mon, 10 Jan 2011 18:30:42 -0800
Subject: (#5171) Made filebucket able to perform diffs

It is now possible to ask the filebucket to diff two files using a URL
of the form:

https://puppet/production/file_bucket_file/md5/{first file hash}?diff_with={second file hash}

The returned diff is a string, the output of the "diff" command.

Paired-with: Paul Berry <paul@puppetlabs.com>
---
 lib/puppet/indirector/file_bucket_file/file.rb | 11 ++++++++++-
 lib/puppet/indirector/indirection.rb           |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

(limited to 'lib/puppet/indirector')

diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb
index 318858aaf..9d9cee793 100644
--- a/lib/puppet/indirector/file_bucket_file/file.rb
+++ b/lib/puppet/indirector/file_bucket_file/file.rb
@@ -15,7 +15,16 @@ module Puppet::FileBucketFile
 
     def find( request )
       checksum, path = request_to_checksum_and_path( request )
-      find_by_checksum( checksum, request.options )
+      file = find_by_checksum( checksum, request.options )
+
+      if file && request.options[:diff_with]
+        hash_protocol = sumtype(checksum)
+        file2 = find_by_checksum( "{#{hash_protocol}}#{request.options[:diff_with]}", request.options )
+        raise "could not find diff_with #{request.options[:diff_with]}" unless file2
+        return `diff #{path_for(file).inspect}/contents #{path_for(file2).inspect}/contents`
+      end
+
+      file
     end
 
     def save( request )
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 309eed7b6..a010c4e40 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -191,7 +191,7 @@ class Puppet::Indirector::Indirection
 
     # Otherwise, return the result from the terminus, caching if appropriate.
     if ! request.ignore_terminus? and result = terminus.find(request)
-      result.expiration ||= self.expiration
+      result.expiration ||= self.expiration if result.respond_to?(:expiration)
       if cache? and request.use_cache?
         Puppet.info "Caching #{self.name} for #{request.key}"
         cache.save request(:save, result, *args)
-- 
cgit