Please review pull request #536: (#9491) Preserve trailing slashes in FileSettings opened by (pcarlisle)

Description:

We use the trailing slash in a FileSetting to determine whether it's a
directory. The change in 97c043f caused trailing slashes to be stripped.
This caused errors like:

change from directory to file failed: Could not set 'file on ensure: Is a directory - /var/lib/puppet/facts

  • Opened: Tue Feb 28 21:23:35 UTC 2012
  • Based on: puppetlabs:2.7.x (2768b9cf3e386cf0e7188533f1af998e3e975928)
  • Requested merge: pcarlisle:ticket/2.7.x/9491-filesetting-munging (77fab88098112105e1c9cd375e7fb0f2cfd5b6c6)

Diff follows:

diff --git a/lib/puppet/util/settings/file_setting.rb b/lib/puppet/util/settings/file_setting.rb
index 9bc9311..46e5aad 100644
--- a/lib/puppet/util/settings/file_setting.rb
+++ b/lib/puppet/util/settings/file_setting.rb
@@ -50,12 +50,10 @@ def use_service_user?
   def munge(value)
     # If it's not a fully qualified path...
     if value.is_a?(String) and value !~ /^\$/ and value != 'false'
-      # Make it one
+      # Preserve trailing slash (stripped by expand_path)
+      isdir = value.to_s =~ /\/$/
       value = File.expand_path(value)
-    end
-    if value.to_s =~ /\/$/
-      @type = :directory
-      return value.sub(/\/$/, '')
+      value += '/' if isdir
     end
     value
   end
diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb
index 74d5090..cc099b3 100755
--- a/spec/unit/util/settings/file_setting_spec.rb
+++ b/spec/unit/util/settings/file_setting_spec.rb
@@ -286,5 +286,14 @@
       @file.to_resource[:links].should == :follow
     end
   end
+
+  describe "when munging a filename" do
+    it "should preserve trailing slashes" do
+      settings = mock 'settings'
+      file = Puppet::Util::Settings::FileSetting.new(:settings => settings, :desc => "eh", :name => :mydir, :section => "mysect")
+      path = @basepath + '/'
+      file.munge(path).should == path
+    end
+  end
 end
 

    

--
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