Skip to content

Commit

Permalink
Merge pull request chocolatey-archive#76 from ferventcoder/tickets/ma…
Browse files Browse the repository at this point in the history
…ster/MODULES-4678_fix_config

(MODULES-4678) Explicitly close config on read
  • Loading branch information
hunner authored May 4, 2017
2 parents 5e3af24 + aed32bf commit 66b46ac
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/chocolateyconfig/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def self.get_configs
raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config)

Puppet.debug("Gathering sources from '#{choco_config}'.")
config = REXML::Document.new File.new(choco_config, 'r')
config = REXML::Document.new File.read(choco_config)

config.elements.to_a( '//add' )
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/chocolateyfeature/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.get_features
raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config)

Puppet.debug("Gathering features from '#{choco_config}'.")
config = REXML::Document.new File.new(choco_config, 'r')
config = REXML::Document.new File.read(choco_config)

config.elements.to_a( '//feature' )
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/chocolateysource/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.get_sources
raise Puppet::ResourceError, "An install was detected, but was unable to locate config file at #{choco_config}." unless PuppetX::Chocolatey::ChocolateyCommon.file_exists?(choco_config)

Puppet.debug("Gathering sources from '#{choco_config}'.")
config = REXML::Document.new File.new(choco_config, 'r')
config = REXML::Document.new File.read(choco_config)

config.elements.to_a( '//source' )
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/provider/chocolateyconfig/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
before :each do
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:new).with(choco_config,"r").returns choco_config_contents
File.expects(:read).with(choco_config).returns choco_config_contents

configs = provider.get_configs
end
Expand Down Expand Up @@ -222,7 +222,7 @@
PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall).at_most_once
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config).at_most_once
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true).at_most_once
File.expects(:new).with(choco_config,"r").returns(choco_config_contents).at_most_once
File.expects(:read).with(choco_config).returns(choco_config_contents).at_most_once

resource[:name] = resource_name
resource[:value] = resource_value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
before :each do
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:new).with(choco_config,"r").returns choco_config_contents
File.expects(:read).with(choco_config).returns choco_config_contents

features = provider.get_features
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/puppet/provider/chocolateysource/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
before :each do
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config)
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true)
File.expects(:new).with(choco_config,"r").returns choco_config_contents
File.expects(:read).with(choco_config).returns choco_config_contents

sources = provider.get_sources
end
Expand Down Expand Up @@ -379,7 +379,7 @@
PuppetX::Chocolatey::ChocolateyCommon.expects(:set_env_chocolateyinstall).at_most_once
PuppetX::Chocolatey::ChocolateyCommon.expects(:choco_config_file).returns(choco_config).at_most_once
PuppetX::Chocolatey::ChocolateyCommon.expects(:file_exists?).with(choco_config).returns(true).at_most_once
File.expects(:new).with(choco_config,"r").returns(choco_config_contents).at_most_once
File.expects(:read).with(choco_config).returns(choco_config_contents).at_most_once

resource[:name] = resource_name
resource[:location] = resource_location
Expand Down

0 comments on commit 66b46ac

Please sign in to comment.