When testing whether a file path is absolute, the regexp was only
handling POSIX style file paths. This commit requires Windows
style file paths to start with a drive letter. A future commit
will refacter the various places we do path validation to
support both Windows drive letters and UNC paths.

Reviewed-by: Jacob Helwig <ja...@puppetlabs.com>
Signed-off-by: Josh Cooper <j...@puppetlabs.com>
---
Local-branch: feature/master/8268-puppet-agent-windows
 lib/puppet/file_serving/fileset.rb |    9 +++++++--
 lib/puppet/node/environment.rb     |    5 +++--
 lib/puppet/parser/type_loader.rb   |    3 ++-
 lib/puppet/type/file.rb            |    2 +-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/puppet/file_serving/fileset.rb 
b/lib/puppet/file_serving/fileset.rb
index f29f70a..b4f1457 100644
--- a/lib/puppet/file_serving/fileset.rb
+++ b/lib/puppet/file_serving/fileset.rb
@@ -59,8 +59,13 @@ class Puppet::FileServing::Fileset
   end
 
   def initialize(path, options = {})
-    path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
-    raise ArgumentError.new("Fileset paths must be fully qualified") unless 
File.expand_path(path) == path
+    if Puppet.features.microsoft_windows?
+      # REMIND: UNC path
+      path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
+    else
+      path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
+    end
+    raise ArgumentError.new("Fileset paths must be fully qualified: #{path}") 
unless File.expand_path(path) == path
 
     @path = path
 
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index dc63197..96fdc3c 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -136,14 +136,15 @@ class Puppet::Node::Environment
   end
 
   def validate_dirs(dirs)
+    dir_regex = Puppet.features.microsoft_windows? ? 
/^[A-Za-z]:#{File::SEPARATOR}/ : /^#{File::SEPARATOR}/
     dirs.collect do |dir|
-      if dir !~ /^#{File::SEPARATOR}/
+      if dir !~ dir_regex
         File.join(Dir.getwd, dir)
       else
         dir
       end
     end.find_all do |p|
-      p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p)
+      p =~ dir_regex && FileTest.directory?(p)
     end
   end
 
diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index 1fba73d..68def06 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -80,7 +80,8 @@ class Puppet::Parser::TypeLoader
 
     loaded_asts = []
     files.each do |file|
-      unless file =~ /^#{File::SEPARATOR}/
+      regex = Puppet.features.microsoft_windows? ? 
/^[A-Za-z]:#{File::SEPARATOR}/ : /^#{File::SEPARATOR}/
+      unless file =~ regex
         file = File.join(dir, file)
       end
       @loading_helper.do_once(file) do
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 72e9a94..8ab12ca 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -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 =~ /^.:\// or value =~ 
/^\/\/[^\/]+\/[^\/]+/))
+      unless (Puppet.features.posix? and value =~ /^\//) or 
(Puppet.features.microsoft_windows? and (value =~ /^[A-Za-z]:\// or value =~ 
/^\/\/[^\/]+\/[^\/]+/))
         fail Puppet::Error, "File paths must be fully qualified, not 
'#{value}'"
       end
     end
-- 
1.7.5.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to