self.map_symlinks

in lib/between_meals/changes/cookbook.rb [40:96]


      def self.map_symlinks(files)
        
        
        
        symlinks = {}
        @cookbook_dirs.each do |dir|
          dir = File.join(@repo_dir, dir)
          
          links = Dir.foreach(dir).select do |d|
            File.symlink?(File.join(dir, d))
          end
          links.each do |link|
            link = File.join(dir, link)
            next if symlinks[link]

            source = File.realpath(link)
            repo = File.join(@repo_dir, '/')
            
            symlinks[link] = {
              'source' => source.gsub(repo, ''),
              'link' => link.gsub(repo, ''),
            }
          end
        end

        
        
        
        links_to_append = []
        symlinks.each_value do |lrp| 
          files.each do |f|
            
            f[:path] += '/' if f[:path] == lrp['link']

            
            
            
            symlink_source_dir = File.join(@repo_dir, lrp['source'])
            if (f[:path] == File.join(lrp['link'], 'metadata.rb') ||
                f[:path] == File.join(lrp['link'], 'metadata.json')) &&
                f[:status] == :deleted &&
                (File.file?(File.join(symlink_source_dir, 'metadata.rb')) ||
                 File.file?(File.join(symlink_source_dir, 'metadata.json')))
              f[:status] = :modified
            end

            next unless f[:path].start_with?(lrp['source'])

            
            l = Marshal.load(Marshal.dump(f))
            l[:path].gsub!(lrp['source'], lrp['link'])
            links_to_append << l
          end
        end
        links_to_append
      end