summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorDavid Schmitt <david@dasz.at>2010-05-21 14:04:51 +0200
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitb51be2809a81e36fee603693f9d70155c49e94fd (patch)
tree381f4fc1e7f356da40ca5d708b23bd57e0908e85 /lib/puppet
parent17a9ad16e9ba13c68cde26a732204d44e63c1146 (diff)
downloadpuppet-b51be2809a81e36fee603693f9d70155c49e94fd.tar.gz
puppet-b51be2809a81e36fee603693f9d70155c49e94fd.tar.xz
puppet-b51be2809a81e36fee603693f9d70155c49e94fd.zip
Expand file type to be able to handle Win32 and UNC paths
Win32 paths start with a drive letter, a colon and a slash; UNC paths start with two slashes, the name of the server and another slash. Signed-off-by: David Schmitt <david@dasz.at>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type/file.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 51865ef49..6d71abce0 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -29,8 +29,8 @@ Puppet::Type.newtype(:file) do
isnamevar
validate do |value|
- # use underlying platform's convention to check for relative paths
- unless File.expand_path(value) == value
+ # accept various path syntaxes: lone slash, posix, win32, unc
+ unless value =~ /^\/$/ or value =~ /^\/[^\/]/ or value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/
fail Puppet::Error,"File paths must be fully qualified, not '#{value}'"
end
end
@@ -44,13 +44,23 @@ Puppet::Type.newtype(:file) do
# and the reverse
unmunge do |value|
- File.join( Puppet::FileCollection.collection.path(value[:index]), value[:name] )
+ basedir = Puppet::FileCollection.collection.path(value[:index])
+ # a lone slash as :name indicates a root dir on windows
+ if value[:name] == '/'
+ basedir
+ else
+ File.join( basedir, value[:name] )
+ end
end
to_canonicalize do |s|
- # Get rid of any duplicate slashes, and remove any trailing slashes unless
- # the title is just a slash, in which case leave it.
- s.gsub(/\/+/, "/").sub(/(.)\/$/,'\1')
+ # * if it looks like a windows path, replace all backslashes with forward slashes
+ # * get rid of any duplicate slashes
+ # * remove any trailing slashes unless the title is just a slash, or a
+ # drive letter in which case leave it
+ # * UNCs in the form //server//share/... keep their initial double slash.
+ s = s.gsub(/\\/, '/') if s =~ /^.:\/\\/ or s =~ /^\/\/[^\/]+\/[^\/]+/
+ s.gsub(/(.)\/+/, '\1/').sub(/([^:])\/$/,'\1')
end
end