Sha256: 86fe4e4947bf597ddeab525ad95ba1b3e55e36cc8b0cddd9fa5946c7c43a12e7

Contents?: true

Size: 1.86 KB

Versions: 37

Compression:

Stored size: 1.86 KB

Contents

require_relative "base_fs_object"
require_relative "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

37 entries across 37 versions & 1 rubygems

Version Path
chef-16.0.275 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-16.0.275-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-16.0.257 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-16.0.257-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.10.12-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.10.12 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.9.17 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.9.17-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.8.23 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.8.23-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.32-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.31 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.31-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.30 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.7.30-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.6.10 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.6.10-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.5.17 lib/chef/chef_fs/file_system/multiplexed_dir.rb
chef-15.5.17-universal-mingw32 lib/chef/chef_fs/file_system/multiplexed_dir.rb