diff options
6 files changed, 31 insertions, 0 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index aa5a6d5a69..6b3e830f8d 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -458,6 +458,7 @@ class Chef # We want to delete just the ones that == POLICY next unless policy.name.rpartition("-")[0] == path[1] policy.delete(false) + FileSystemCache.instance.delete!(policy.file_path) found_policy = true end raise ChefZero::DataStore::DataNotFoundError.new(path) if !found_policy diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb index a768bcf971..3e1edc8d62 100644 --- a/lib/chef/chef_fs/file_system/repository/base_file.rb +++ b/lib/chef/chef_fs/file_system/repository/base_file.rb @@ -16,6 +16,8 @@ # limitations under the License. # +require "chef/chef_fs/file_system_cache" + class Chef module ChefFS module FileSystem @@ -99,6 +101,7 @@ class Chef end def delete(_) + FileSystemCache.instance.delete!(file_path) File.delete(file_path) rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb index 9d1538e46e..4019c6985b 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb @@ -120,6 +120,7 @@ class Chef end def delete(recurse) + FileSystemCache.instance.delete!(file_path) begin if dir? if !recurse diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb index 43f5719822..328cf92b03 100644 --- a/lib/chef/chef_fs/file_system/repository/directory.rb +++ b/lib/chef/chef_fs/file_system/repository/directory.rb @@ -84,6 +84,7 @@ class Chef if child.exists? raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, child) end + FileSystemCache.instance.delete!(child.file_path) if file_contents child.write(file_contents) else @@ -122,6 +123,7 @@ class Chef raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self) end begin + FileSystemCache.instance.delete!(file_path) Dir.mkdir(file_path) rescue Errno::EEXIST raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self) @@ -138,6 +140,7 @@ class Chef raise MustDeleteRecursivelyError.new(self, $!) end FileUtils.rm_r(file_path) + FileSystemCache.instance.delete!(file_path) else raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end @@ -149,6 +152,10 @@ class Chef protected + def write(data) + raise FileSystemError.new(self, nil, "attempted to write to a directory entry") + end + def make_child_entry(child_name) raise "Not Implemented" end diff --git a/lib/chef/chef_fs/file_system_cache.rb b/lib/chef/chef_fs/file_system_cache.rb index 38b4fda7ad..a9d8d8bfe4 100644 --- a/lib/chef/chef_fs/file_system_cache.rb +++ b/lib/chef/chef_fs/file_system_cache.rb @@ -49,6 +49,17 @@ class Chef val end + def delete!(path) + parent = _get_parent(path) + Chef::Log.debug("Deleting parent #{parent} and #{path} from FileSystemCache") + if @cache.key?(path) + @cache.delete(path) + end + if !parent.nil? && @cache.key?(parent) + @cache.delete(parent) + end + end + def fetch(path) if @cache.key?(path) @cache[path] @@ -57,6 +68,13 @@ class Chef end end + private + + def _get_parent(path) + parts = ChefFS::PathUtils.split(path) + return nil if parts.nil? || parts.length < 2 + ChefFS::PathUtils.join(*parts[0..-2]) + end end end end diff --git a/spec/unit/chef_fs/file_system/repository/directory_spec.rb b/spec/unit/chef_fs/file_system/repository/directory_spec.rb index e050181be9..6e53e52966 100644 --- a/spec/unit/chef_fs/file_system/repository/directory_spec.rb +++ b/spec/unit/chef_fs/file_system/repository/directory_spec.rb @@ -76,6 +76,7 @@ describe Chef::ChefFS::FileSystem::Repository::Directory do context "#create_child" do it "creates a new TestFile" do expect(TestFile).to receive(:new).with("test_child", test_directory).and_return(file_double) + allow(file_double).to receive(:file_path).and_return("#{test_directory}/test_child") expect(file_double).to receive(:write).with("test") test_directory.create_child("test_child", "test") end |