From 9e59aeb7db0a61123538bbbcfdc9fc14356e99ca Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Wed, 5 Feb 2014 11:30:41 -0800 Subject: [PATCH] (maint) Reset facter search path when resetting facts The previous implementation of Facter search paths was only additive and there was no way to remove Facter search paths once added. This is especially problematic when running the Puppet specs which wind up reloading Facter frequently and adding search paths, and can wind up adding thousands of meaningless paths. This commit resets the Facter search path on `Facter.reset` so that when facts are reset, the known search pats are reset as well. --- lib/facter.rb | 13 +++++++++++-- spec/unit/facter_spec.rb | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index 68b3d7b0fc..e85c99b1a2 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -184,6 +184,7 @@ def self.clear # @api public def self.reset @collection = nil + reset_search_path! end # Loads all facts. @@ -195,8 +196,6 @@ def self.loadfacts collection.load_all end - @search_path = [] - # Register directories to be searched for facts. The registered directories # must be absolute paths or they will be ignored. # @@ -218,6 +217,16 @@ def self.search_path @search_path.dup end + # Reset the Facter search directories. + # + # @api private + # @return [void] + def self.reset_search_path! + @search_path = [] + end + + reset_search_path! + # Registers directories to be searched for external facts. # # @param dirs [Array] directories to search diff --git a/spec/unit/facter_spec.rb b/spec/unit/facter_spec.rb index 6817446002..1b87ef3634 100755 --- a/spec/unit/facter_spec.rb +++ b/spec/unit/facter_spec.rb @@ -109,7 +109,7 @@ end describe "when registering directories to search" do - after { Facter.instance_variable_set("@search_path", []) } + after { Facter.reset_search_path! } it "should allow registration of a directory" do Facter.search "/my/dir"