diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2011-03-24 17:51:59 -0700 |
|---|---|---|
| committer | Jesse Wolfe <jes5199@gmail.com> | 2011-03-25 15:20:39 -0700 |
| commit | daaa048a8d8829ad509b4a456826cc8a33cf6444 (patch) | |
| tree | 817971bd3c1a7e8383bc3243833b8d1367e768dc /lib | |
| parent | c7f6e5ee743c061c020521651360bba240ae4519 (diff) | |
| download | puppet-daaa048a8d8829ad509b4a456826cc8a33cf6444.tar.gz puppet-daaa048a8d8829ad509b4a456826cc8a33cf6444.tar.xz puppet-daaa048a8d8829ad509b4a456826cc8a33cf6444.zip | |
(#5477) Allow watch_file to watch non-existent files, especially site.pp
The watch_file mechanism would refuse to monitor paths to files that
didn't exist. This patch makes it possible to watch a file that hasn't
been created yet, so when it is created, you manifests will get
reparsed.
Paired-With: Max Martin <max@puppetlabs.com>
Reviewed-By: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/node/environment.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/parser/lexer.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/parser/parser_support.rb | 1 | ||||
| -rw-r--r-- | lib/puppet/simple_graph.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/util/loadedfile.rb | 6 |
5 files changed, 8 insertions, 13 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index 7877b7f73..d50530618 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -76,7 +76,7 @@ class Puppet::Node::Environment # per environment semantics with an efficient most common cases; we almost # always just return our thread's known-resource types. Only at the start # of a compilation (after our thread var has been set to nil) or when the - # environment has changed do we delve deeper. + # environment has changed do we delve deeper. Thread.current[:known_resource_types] = nil if (krt = Thread.current[:known_resource_types]) && krt.environment != self Thread.current[:known_resource_types] ||= synchronize { if @known_resource_types.nil? or @known_resource_types.stale? @@ -128,7 +128,7 @@ class Puppet::Node::Environment to_s.to_sym end - # The only thing we care about when serializing an environment is its + # The only thing we care about when serializing an environment is its # identity; everything else is ephemeral and should not be stored or # transmitted. def to_zaml(z) @@ -156,7 +156,6 @@ class Puppet::Node::Environment parser.string = code else file = Puppet.settings.value(:manifest, name.to_s) - return empty_parse_result unless File.exist?(file) parser.file = file end parser.parse diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 4050adeb8..2f416615e 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -312,7 +312,8 @@ class Puppet::Parser::Lexer def file=(file) @file = file @line = 1 - @scanner = StringScanner.new(File.read(file)) + contents = File.exists?(file) ? File.read(file) : "" + @scanner = StringScanner.new(contents) end def shift_token @@ -547,7 +548,7 @@ class Puppet::Parser::Lexer value,terminator = slurpstring('"$') token_queue << [TOKENS[token_type[terminator]],preamble+value] if terminator != '$' or @scanner.scan(/\{/) - token_queue.shift + token_queue.shift elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]}) token_queue << [TOKENS[:VARIABLE],var_name] tokenize_interpolated_string(DQ_continuation_token_types) diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 746aa0f90..7888fe1dc 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -79,7 +79,6 @@ class Puppet::Parser::Parser unless file =~ /\.pp$/ file = file + ".pp" end - raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file) end raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file) diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb index e39aa8770..ed71a64f3 100644 --- a/lib/puppet/simple_graph.rb +++ b/lib/puppet/simple_graph.rb @@ -367,7 +367,7 @@ class Puppet::SimpleGraph return [] unless ns = (options[:direction] == :in) ? @in_to[v] : @out_from[v] (options[:type] == :edges) ? ns.values.flatten : ns.keys end - + # Take container information from another graph and use it # to replace any container vertices with their respective leaves. # This creates direct relationships where there were previously @@ -387,7 +387,7 @@ class Puppet::SimpleGraph children = other.adjacent(container, :direction => :out) # MQR TODO: Luke suggests that it should be possible to refactor the system so that - # container nodes are retained, thus obviating the need for the whit. + # container nodes are retained, thus obviating the need for the whit. children = [whit_class.new(:name => container.name, :catalog => other)] if children.empty? # First create new edges for each of the :in edges diff --git a/lib/puppet/util/loadedfile.rb b/lib/puppet/util/loadedfile.rb index 735dba459..d2f5d0923 100755 --- a/lib/puppet/util/loadedfile.rb +++ b/lib/puppet/util/loadedfile.rb @@ -34,10 +34,6 @@ module Puppet # Create the file. Must be passed the file path. def initialize(file) @file = file - unless FileTest.exists?(@file) - raise Puppet::NoSuchFile, - "Can not use a non-existent file for parsing" - end @statted = 0 @stamp = nil @tstamp = stamp @@ -50,7 +46,7 @@ module Puppet @statted = Time.now.to_i begin @stamp = File.stat(@file).ctime - rescue Errno::ENOENT + rescue Errno::ENOENT, Errno::ENOTDIR @stamp = Time.now end end |
