Sha256: 18c596b93f8840ad9604cfe8cca55e99d5104243da71b2647ff23eedd41025c0

Contents?: true

Size: 1.89 KB

Versions: 29

Compression:

Stored size: 1.89 KB

Contents

require "chef/chef_fs/file_system/base_fs_object"
require "chef/chef_fs/file_system/nonexistent_fs_object"

class Chef
  module ChefFS
    module FileSystem
      class MultiplexedDir < BaseFSDir
        def initialize(*multiplexed_dirs)
          @multiplexed_dirs = multiplexed_dirs.flatten
          super(@multiplexed_dirs[0].name, @multiplexed_dirs[0].parent)
        end

        attr_reader :multiplexed_dirs

        def write_dir
          multiplexed_dirs[0]
        end

        def children
          result = []
          seen = {}
            # If multiple things have the same name, the first one wins.
          multiplexed_dirs.each do |dir|
            dir.children.each do |child|
              if seen[child.name]
                Chef::Log.warn("Child with name '#{child.name}' found in multiple directories: #{seen[child.name].path_for_printing} and #{child.path_for_printing}") unless seen[child.name].path_for_printing == child.path_for_printing
              else
                result << child
                seen[child.name] = child
              end
            end
          end
          result
        end

        def make_child_entry(name)
          result = nil
          multiplexed_dirs.each do |dir|
            child_entry = dir.child(name)
            if child_entry.exists?
              if result
                Chef::Log.trace("Child with name '#{child_entry.name}' found in multiple directories: #{result.parent.path_for_printing} and #{child_entry.parent.path_for_printing}")
              else
                result = child_entry
              end
            end
          end
          result
        end

        def can_have_child?(name, is_dir)
          write_dir.can_have_child?(name, is_dir)
        end

        def create_child(name, file_contents = nil)
          @children = nil
          write_dir.create_child(name, file_contents)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
chef-14.15.6 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.15.6-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.29 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.29-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.25-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.25 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.14-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.14.14 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.13.11 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.12.9 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.12.3 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.11.21 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.10.9 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.9.13 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.8.12 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.7.17 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.6.47 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.5.33 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.5.27 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-14.5.27-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb