From 9a41c35a5160dbba10ec00f3ed45bafad3ebd06a Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Tue, 24 Nov 2009 09:09:07 -0800 Subject: Fixing #2791 fs_find should follow symlinks Symlinks confuse the "What file system am I on?" logic. This patch just runs the paths through a beefed up version of the standard 'realpath' method. Includes some of Markus's suggested changes. Signed-off-by: Jesse Wolfe --- lib/puppet/util/selinux.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 25d86f77e..3eff03996 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -13,6 +13,8 @@ rescue LoadError # Nothing end +require 'pathname' + module Puppet::Util::SELinux def selinux_support? @@ -185,9 +187,19 @@ module Puppet::Util::SELinux return mntpoint end + def realpath(path) + path, rest = Pathname.new(path), [] + path, rest = path.dirname, [path.basename] + rest while ! path.exist? + File.join( path.realpath, *rest ) + end + + def parent_directory(path) + Pathname.new(path).dirname.to_s + end + # Internal helper function to return which type of filesystem a # given file path resides on - def find_fs(file) + def find_fs(path) unless mnts = read_mounts() return nil end @@ -198,13 +210,12 @@ module Puppet::Util::SELinux # Just in case: return something if you're down to "/" or "" # Remove the last slash and everything after it, # and repeat with that as the file for the next loop through. - ary = file.split('/') - while not ary.empty? do - path = ary.join('/') + path = realpath(path) + while not path.empty? do if mnts.has_key?(path) return mnts[path] end - ary.pop + path = parent_directory(path) end return mnts['/'] end -- cgit