+1

On Dec 31, 2009, at 11:56 AM, Markus Roberts wrote:

> The first patch for #2994, to which this is an extension, exposed
> the fact that checksums were not being included in the metadata
> for followed links; checksums are needed for managing the contents
> of files that are represented on the server as links (links =>  
> follow).
>
> This patch adds checksums for followed links and tests to confirm that
> it works as expected.
>
> Signed-off-by: Markus Roberts <[email protected]>
> ---
> lib/puppet/file_serving/metadata.rb |   10 +++----
> spec/unit/file_serving/metadata.rb  |   46 +++++++++++++++++++++ 
> +------------
> 2 files changed, 34 insertions(+), 22 deletions(-)
>
> diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/ 
> file_serving/metadata.rb
> index 275a090..678a4ff 100644
> --- a/lib/puppet/file_serving/metadata.rb
> +++ b/lib/puppet/file_serving/metadata.rb
> @@ -22,18 +22,15 @@ class Puppet::FileServing::Metadata <  
> Puppet::FileServing::Base
>     PARAM_ORDER = [:mode, :ftype, :owner, :group]
>
>     def attributes_with_tabs
> +        raise(ArgumentError, "Cannot manage files of type  
> #{ftype}") unless ['file','directory','link'].include? ftype
>         desc = []
>         PARAM_ORDER.each { |check|
>             check = :ftype if check == :type
>             desc << send(check)
>         }
>
> -        case ftype
> -        when "file", "directory"; desc << checksum
> -        when "link"; desc << @destination
> -        else
> -            raise ArgumentError, "Cannot manage files of type %s" %  
> ftype
> -        end
> +        desc << checksum     if ftype == 'file' or ftype ==  
> 'directory' or (ftype == 'link' and @links == :follow)
> +        desc << @destination  
> if                                             ftype == 'link' and  
> @links != :follow
>
>         return desc.join("\t")
>     end
> @@ -66,6 +63,7 @@ class Puppet::FileServing::Metadata <  
> Puppet::FileServing::Base
>             @checksum = ("{%s}" % @checksum_type) + send("%s_file" %  
> @checksum_type, path).to_s
>         when "link"
>             @destination = File.readlink(real_path)
> +            @checksum = ("{%s}" % @checksum_type) + send("%s_file"  
> % @checksum_type, real_path).to_s if @links == :follow
>         else
>             raise ArgumentError, "Cannot manage files of type %s" %  
> stat.ftype
>         end
> diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/ 
> file_serving/metadata.rb
> index 38240f7..a3078fa 100755
> --- a/spec/unit/file_serving/metadata.rb
> +++ b/spec/unit/file_serving/metadata.rb
> @@ -230,23 +230,37 @@ describe Puppet::FileServing::Metadata, " when  
> collecting attributes" do
> end
>
> describe Puppet::FileServing::Metadata, " when pointing to a link" do
> -    it "should store the destination of the link in :destination if  
> links are :manage" do
> -        file = Puppet::FileServing::Metadata.new("/base/path/my/ 
> file", :links => :manage)
> -
> -        File.expects(:lstat).with("/base/path/my/file").returns  
> stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755)
> -        File.expects(:readlink).with("/base/path/my/file").returns  
> "/some/other/path"
> -
> -        file.collect
> -        file.destination.should == "/some/other/path"
> +    describe "when links are managed" do
> +        before do
> +             @file = Puppet::FileServing::Metadata.new("/base/path/ 
> my/file", :links => :manage)
> +             File.expects(:lstat).with("/base/path/my/ 
> file").returns stub("stat", :uid => 1, :gid => 2, :ftype =>  
> "link", :mode => 0755)
> +             File.expects(:readlink).with("/base/path/my/ 
> file").returns "/some/other/path"
> +        end
> +        it "should store the destination of the link  
> in :destination if links are :manage" do
> +            @file.collect
> +            @file.destination.should == "/some/other/path"
> +        end
> +        it "should not collect the checksum if links are :manage" do
> +            @file.collect
> +            @file.checksum.should be_nil
> +        end
>     end
>
> -    it "should not collect the checksum" do
> -        file = Puppet::FileServing::Metadata.new("/base/path/my/ 
> file", :links => :manage)
> -
> -        File.expects(:lstat).with("/base/path/my/file").returns  
> stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755)
> -        File.expects(:readlink).with("/base/path/my/file").returns  
> "/some/other/path"
> -
> -        file.collect
> -        file.checksum.should be_nil
> +    describe "when links are followed" do
> +        before do
> +            @file = Puppet::FileServing::Metadata.new("/base/path/ 
> my/file", :links => :follow)
> +            File.expects(:stat).with("/base/path/my/file").returns  
> stub("stat", :uid => 1, :gid => 2, :ftype => "file", :mode => 0755)
> +            File.expects(:readlink).with("/base/path/my/file").never
> +            @checksum = Digest::MD5.hexdigest("some content\n")
> +            @file.stubs(:md5_file).returns(@checksum)
> +        end
> +        it "should not store the destination of the link  
> in :destination if links are :follow" do
> +            @file.collect
> +            @file.destination.should be_nil
> +        end
> +        it "should collect the checksum if links are :follow" do
> +            @file.collect
> +            @file.checksum.should == "{md5...@checksum}"
> +        end
>     end
> end
> -- 
> 1.6.4
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected] 
> .
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en 
> .
>
>


-- 
To get back my youth I would do anything in the world, except take
exercise, get up early, or be respectable. -- Oscar Wilde
---------------------------------------------------------------------
Luke Kanies  -|-   http://reductivelabs.com   -|-   +1(615)594-8199

--

You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.


Reply via email to