Class: FPM::Fry::Plugin::Config::Callback Private

Inherits:
Struct
  • Object
show all
Defined in:
lib/fpm/fry/plugin/config.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filesObject

Returns the value of attribute files

Returns:

  • (Object)

    the current value of files



16
17
18
# File 'lib/fpm/fry/plugin/config.rb', line 16

def files
  @files
end

Instance Method Details

#call(_, package) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fpm/fry/plugin/config.rb', line 18

def call(_, package)
  chroot = FPM::Fry::Chroot.new(package.staging_path)
  prefix_length = package.staging_path.size + 1
  candidates = []
  # Sorting is important so that more specific rules override more generic 
  # rules.
  keys = files.keys.sort_by(&:size)
  keys.each do | key |
    if files[key]
      # Inclusion rule. Crawl file system for candidates
      begin
        lstat = chroot.lstat( key )
        if lstat.symlink?
          package.logger.warn("Config file is a symlink",
                               path: key,
                               plugin: 'config',
                               documentation: 'https://github.com/xing/fpm-fry/wiki/Plugin-config#config-path-not-foun://github.com/xing/fpm-fry/wiki/Plugin-config#config-file-is-a-symlink')
          next
        end
        chroot.find( key ) do | path |
          lstat = chroot.lstat(path)
          if lstat.symlink?
            package.logger.debug("Ignoring symlink",
                                 path: path,
                                 plugin: 'config')
            throw :prune
          elsif lstat.file?
            candidates << path
          end
        end
      rescue Errno::ENOENT
        package.logger.warn("Config path not found",
                            path: key,
                            plugin: 'config',
                            documentation: 'https://github.com/xing/fpm-fry/wiki/Plugin-config#config-path-not-found')
      end
    else
      # Exclusion rule. Remove matching candidates
      keydir = key + "/"
      candidates.reject!{ |can| 
        can.start_with?(keydir) || can == key
      }
    end
  end
  package.config_files |= candidates
end