[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
James Turnbull
james at lovedthanlost.net
Fri Jan 23 14:20:51 UTC 2009
The following commit has been merged in the master branch:
commit 0d118a5f22e8f2c9f72b51e8848514d779c09d36
Author: Andrew Shafer <andrew at reductivelabs.com>
Date: Fri Aug 22 23:53:08 2008 -0600
Fix leaking LoadedFile when adding templates to be watched
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index d70722f..853d6aa 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -95,11 +95,10 @@ class Puppet::Parser::Parser
raise Puppet::Error, "Could not find file %s" % file
end
end
- if @files.detect { |f| f.file == file }
- raise Puppet::AlreadyImportedError.new("Import loop detected")
- else
- @files << Puppet::Util::LoadedFile.new(file)
+ if check_and_add_to_watched_files(file)
@lexer.file = file
+ else
+ raise Puppet::AlreadyImportedError.new("Import loop detected")
end
end
@@ -216,7 +215,7 @@ class Puppet::Parser::Parser
# Initialize or reset all of our variables.
def initvars
@lexer = Puppet::Parser::Lexer.new()
- @files = []
+ @files = {}
@loaded = []
end
@@ -435,8 +434,8 @@ class Puppet::Parser::Parser
# See if any of the files have changed.
def reparse?
- if file = @files.detect { |file| file.changed? }
- return file.stamp
+ if file = @files.detect { |name, file| file.changed? }
+ return file[1].stamp
else
return false
end
@@ -449,12 +448,18 @@ class Puppet::Parser::Parser
# Add a new file to be checked when we're checking to see if we should be
# reparsed. This is basically only used by the TemplateWrapper to let the
# parser know about templates that should be parsed.
- def watch_file(*files)
- files.each do |file|
- unless file.is_a? Puppet::Util::LoadedFile
- file = Puppet::Util::LoadedFile.new(file)
- end
- @files << file
+ def watch_file(filename)
+ check_and_add_to_watched_files(filename)
+ end
+
+ private
+
+ def check_and_add_to_watched_files(filename)
+ unless @files.include?(filename)
+ @files[filename] = Puppet::Util::LoadedFile.new(filename)
+ return true
+ else
+ return false
end
end
end
diff --git a/test/language/parser.rb b/test/language/parser.rb
index cdd1329..fc8452b 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -1208,5 +1208,13 @@ file { "/tmp/yayness":
parser.import("test")
end
end
+
+ def test_watch_file_only_once
+ FileTest.stubs(:exists?).returns(true)
+ parser = mkparser
+ parser.watch_file("doh")
+ parser.watch_file("doh")
+ assert_equal(1, parser.files.select { |name, file| file.file == "doh" }.length, "Length of watched 'doh' files was not 1")
+ end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list