summaryrefslogtreecommitdiffstats
path: root/lib/puppet/type/file.rb
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-08-02 11:04:26 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-08-19 13:52:58 -0700
commit37f87b709598b48bc8b562422da27cc73cc1eff1 (patch)
treeb5f96e5e69556e6031a8533960802fac268e88b7 /lib/puppet/type/file.rb
parent4a6d61717eb54a0cefff87bf67ae62df1e3b4317 (diff)
downloadpuppet-37f87b709598b48bc8b562422da27cc73cc1eff1.tar.gz
puppet-37f87b709598b48bc8b562422da27cc73cc1eff1.tar.xz
puppet-37f87b709598b48bc8b562422da27cc73cc1eff1.zip
Treat Windows absolute paths as absolute paths
Previously, we only considered files that matched the *nix concept of 'absolute' as being absolute paths. Since absolute paths on Windows look more like URLs with this world-view, we need to specifically look for the Windows absolute paths, and treat them as such. We will still treat *nix absolute paths as absolute on Windows, even though they are actually relative to the "current" drive. We do not currently limit which "style" of absolute path is allowed based on what the agent is. Reviewed-by: Nick Lewis <nick@puppetlabs.com> (cherry picked from commit 568d25ee10effd5e87c57cdc8c24280eabf9cd93)
Diffstat (limited to 'lib/puppet/type/file.rb')
-rw-r--r--lib/puppet/type/file.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 5398621f5..d3c66bc02 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -23,7 +23,7 @@ Puppet::Type.newtype(:file) do
location, rather than using native resources, please contact
Puppet Labs and we can hopefully work with you to develop a
native resource to support what you are doing.
-
+
**Autorequires:** If Puppet is managing the user or group that owns a file, the file resource will autorequire them. If Puppet is managing any parent directories of a file, the file resource will autorequire them."
def self.title_patterns
@@ -36,7 +36,7 @@ Puppet::Type.newtype(:file) do
validate do |value|
# accept various path syntaxes: lone slash, posix, win32, unc
- unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^[A-Za-z]:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
+ unless (Puppet.features.posix? and value =~ /^\//) or (value =~ /^[A-Za-z]:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)
fail Puppet::Error, "File paths must be fully qualified, not '#{value}'"
end
end
@@ -44,7 +44,21 @@ Puppet::Type.newtype(:file) do
# convert the current path in an index into the collection and the last
# path name. The aim is to use less storage for all common paths in a hierarchy
munge do |value|
- path, name = ::File.split(value.gsub(/\/+/,'/'))
+ # We need to save off, and remove the volume designator in the
+ # path if it is there, since File.split does not handle paths
+ # with volume designators properly, except when run on Windows.
+ # Since we are potentially compiling a catalog for a Windows
+ # machine on a non-Windows master, we need to handle this
+ # ourselves.
+ optional_volume_designator = value.match(/^([a-z]:)[\/\\].*/i)
+ value_without_designator = value.sub(/^(?:[a-z]:)?(.*)/i, '\1')
+
+ path, name = ::File.split(value_without_designator.gsub(/\/+/,'/'))
+
+ if optional_volume_designator
+ path = optional_volume_designator[1] + path
+ end
+
{ :index => Puppet::FileCollection.collection.index(path), :name => name }
end