From 20e5222de71f68780063d774e83fd1debe64ba86 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 26 Oct 2009 22:54:38 -0700 Subject: Fixing #2689 - file owner warnings are reduced We now only warn when there's an actual change to make, and we only make one warning per process run. Signed-off-by: Luke Kanies --- lib/puppet/type/file/owner.rb | 11 +++++++---- spec/unit/type/file/owner.rb | 14 ++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/puppet/type/file/owner.rb b/lib/puppet/type/file/owner.rb index 1dff59cb3..e5ca06a86 100755 --- a/lib/puppet/type/file/owner.rb +++ b/lib/puppet/type/file/owner.rb @@ -28,10 +28,7 @@ module Puppet end def insync?(current) - unless Puppet::Util::SUIDManager.uid == 0 - warning "Cannot manage ownership unless running as root" - return true - end + return true unless should @should.each do |value| if value =~ /^\d+$/ @@ -44,6 +41,12 @@ module Puppet return true if uid == current end + + unless Puppet::Util::SUIDManager.uid == 0 + warnonce "Cannot manage ownership unless running as root" + return true + end + return false end diff --git a/spec/unit/type/file/owner.rb b/spec/unit/type/file/owner.rb index 1ea01cbc7..62f7b0ae5 100755 --- a/spec/unit/type/file/owner.rb +++ b/spec/unit/type/file/owner.rb @@ -55,11 +55,13 @@ describe property do describe "when determining if the file is in sync" do describe "and not running as root" do - it "should warn and return true" do - @owner.should = 10 + it "should warn once and return true" do Puppet::Util::SUIDManager.expects(:uid).returns 1 - @owner.expects(:warning) - @owner.must be_insync("whatever") + + @owner.expects(:warnonce) + + @owner.should = [10] + @owner.must be_insync(20) end end @@ -67,6 +69,10 @@ describe property do Puppet::Util::SUIDManager.stubs(:uid).returns 0 end + it "should be in sync if 'should' is not provided" do + @owner.must be_insync(10) + end + it "should directly compare the owner values if the desired owner is an integer" do @owner.should = [10] @owner.must be_insync(10) -- cgit