Sha256: 1dc2ac45458e61ce28658f4f06457a57b6580209fc444adb0a82df5eefb5f1cb

Contents?: true

Size: 1.37 KB

Versions: 110

Compression:

Stored size: 1.37 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
          begin
            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}")
                else
                  result << child
                  seen[child.name] = child
                end
              end
            end
            result
          end
        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

110 entries across 110 versions & 1 rubygems

Version Path
chef-12.4.3-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.3 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.2-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.2 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.5.0.alpha.1 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.1-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.1 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0.rc.2 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0.rc.2-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0.rc.0 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.4.0.rc.0-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-11.18.12-x86-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-11.18.12 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.3.0-x86-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.3.0 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.3.0.rc.0-x86-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.3.0.rc.0 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-12.2.1-x86-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb