From 319822af6d58c3e0c391e86cfd836ec31de43c67 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Wed, 11 Feb 2009 14:33:48 -0600 Subject: Fixing #1869 - autoloaded files should never leak exceptions Ruby's exception hierarchy is a bit strange, in that only exceptions that sub RuntimeError are caught by default. This patch explicitly catches the base class, Exception, which means that LoadError, SyntaxError, and any RuntimeErrors will all be caught. This is done for both load() and loadall(); load() uses Kernel.load, but loadall() uses Kernel.require. Signed-off-by: Luke Kanies --- lib/puppet/util/autoload.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 535d9ef2e..0c80f8b06 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -78,7 +78,7 @@ class Puppet::Util::Autoload name = symbolize(name) loaded name, file return true - rescue LoadError => detail + rescue Exception => detail # I have no idea what's going on here, but different versions # of ruby are raising different errors on missing files. unless detail.to_s =~ /^no such file/i @@ -115,7 +115,7 @@ class Puppet::Util::Autoload begin Kernel.require file loaded(name, file) - rescue => detail + rescue Exception => detail if Puppet[:trace] puts detail.backtrace end -- cgit From 4e89156b21b287b683c27a4cd691856c4e378a62 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:13:28 -0600 Subject: Migrated FileType tests to spec, and fleshed them out a bit. Signed-off-by: Luke Kanies --- lib/puppet/util/filetype.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 60cbc77e7..60380d5f1 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -74,7 +74,7 @@ class Puppet::Util::FileType # Back the file up before replacing it. def backup - bucket.backup(@path) if FileTest.exists?(@path) + bucket.backup(@path) if File.exists?(@path) end # Pick or create a filebucket to use. @@ -92,7 +92,7 @@ class Puppet::Util::FileType newfiletype(:flat) do # Read the file. def read - if File.exists?(@path) + if File.exist?(@path) File.read(@path) else return nil @@ -101,7 +101,7 @@ class Puppet::Util::FileType # Remove the file. def remove - if File.exists?(@path) + if File.exist?(@path) File.unlink(@path) end end -- cgit From 53f15b9208a3271e944c687b8d0e670d422fb832 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:42:09 -0600 Subject: Removing the apparently obsolete netinfo filetype. Signed-off-by: Luke Kanies --- lib/puppet/util/filetype.rb | 88 --------------------------------------------- 1 file changed, 88 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 60380d5f1..137ef0c67 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -250,92 +250,4 @@ class Puppet::Util::FileType output_file.delete end end - - # Treat netinfo tables as a single file, just for simplicity of certain - # types - newfiletype(:netinfo) do - class << self - attr_accessor :format - end - def read - %x{nidump -r /#{@path} /} - end - - # This really only makes sense for cron tabs. - def remove - %x{nireport / /#{@path} name}.split("\n").each do |name| - newname = name.gsub(/\//, '\/').sub(/\s+$/, '') - output = %x{niutil -destroy / '/#{@path}/#{newname}'} - - unless $? == 0 - raise Puppet::Error, "Could not remove %s from %s" % - [name, @path] - end - end - end - - # Convert our table to an array of hashes. This only works for - # handling one table at a time. - def to_array(text = nil) - unless text - text = read - end - - hash = nil - - # Initialize it with the first record - records = [] - text.split("\n").each do |line| - next if line =~ /^[{}]$/ # Skip the wrapping lines - next if line =~ /"name" = \( "#{@path}" \)/ # Skip the table name - next if line =~ /CHILDREN = \(/ # Skip this header - next if line =~ /^ \)/ # and its closer - - # Now we should have nothing but records, wrapped in braces - - case line - when /^\s+\{/: hash = {} - when /^\s+\}/: records << hash - when /\s+"(\w+)" = \( (.+) \)/ - field = $1 - values = $2 - - # Always use an array - hash[field] = [] - - values.split(/, /).each do |value| - if value =~ /^"(.*)"$/ - hash[field] << $1 - else - raise ArgumentError, "Could not match value %s" % value - end - end - else - raise ArgumentError, "Could not match line %s" % line - end - end - - records - end - - def write(text) - text.gsub!(/^#.*\n/,'') - text.gsub!(/^$/,'') - if text == "" or text == "\n" - self.remove - return - end - unless format = self.class.format - raise Puppe::DevError, "You must define the NetInfo format to inport" - end - IO.popen("niload -d #{format} . 1>/dev/null 2>/dev/null", "w") { |p| - p.print text - } - - unless $? == 0 - raise ArgumentError, "Failed to write %s" % @path - end - end - end end - -- cgit From d5a193a594bbc2194dbf1e5264369ebea0e55880 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 15 Jan 2009 15:44:09 -0600 Subject: Fixing #1541 - ParsedFile only backs up files once per transaction This moves responsibility for backups from the filetype to the consumer of the filetype, but only ParsedFile actually uses filetypes. Signed-off-by: Luke Kanies --- lib/puppet/util/filetype.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb index 137ef0c67..5d4ba1440 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -108,7 +108,6 @@ class Puppet::Util::FileType # Overwrite the file. def write(text) - backup() require "tempfile" tf = Tempfile.new("puppet") tf.print text; tf.flush -- cgit