Class: Puppet::FileServing::Fileset

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/file_serving/fileset.rb

Overview

Operate recursively on a path, returning a set of file paths.

Defined Under Namespace

Classes: FileSetEntry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Fileset

Returns a new instance of Fileset.

Raises:

  • (ArgumentError)


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
# File 'lib/puppet/file_serving/fileset.rb', line 27

def initialize(path, options = {})
  if Puppet.features.microsoft_windows?
    # REMIND: UNC path
    path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
  else
    path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
  end
  raise ArgumentError.new(_("Fileset paths must be fully qualified: %{path}") % { path: path }) unless Puppet::Util.absolute_path?(path)

  @path = path

  # Set our defaults.
  self.ignore = []
  self.links = :manage
  @recurse = false
  @recurselimit = :infinite

  if options.is_a?(Puppet::Indirector::Request)
    initialize_from_request(options)
  else
    initialize_from_hash(options)
  end

  raise ArgumentError.new(_("Fileset paths must exist")) unless valid?(path)
  #TRANSLATORS "recurse" and "recurselimit" are parameter names and should not be translated
  raise ArgumentError.new(_("Fileset recurse parameter must not be a number anymore, please use recurselimit")) if @recurse.is_a?(Integer)
end

Instance Attribute Details

#checksum_typeObject

Returns the value of attribute checksum_type.



8
9
10
# File 'lib/puppet/file_serving/fileset.rb', line 8

def checksum_type
  @checksum_type
end

#ignoreObject

Returns the value of attribute ignore.



7
8
9
# File 'lib/puppet/file_serving/fileset.rb', line 7

def ignore
  @ignore
end

Returns the value of attribute links.



7
8
9
# File 'lib/puppet/file_serving/fileset.rb', line 7

def links
  @links
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/puppet/file_serving/fileset.rb', line 7

def path
  @path
end

#recurseObject

Returns the value of attribute recurse.



8
9
10
# File 'lib/puppet/file_serving/fileset.rb', line 8

def recurse
  @recurse
end

#recurselimitObject

Returns the value of attribute recurselimit.



8
9
10
# File 'lib/puppet/file_serving/fileset.rb', line 8

def recurselimit
  @recurselimit
end

Class Method Details

.merge(*filesets) ⇒ Object

Produce a hash of files, with merged so that earlier files with the same postfix win. E.g., /dir1/subfile beats /dir2/subfile. It’s a hash because we need to know the relative path of each file, and the base directory.

This will probably only ever be used for searching for plugins.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet/file_serving/fileset.rb', line 15

def self.merge(*filesets)
  result = {}

  filesets.each do |fileset|
    fileset.files.each do |file|
      result[file] ||= fileset.path
    end
  end

  result
end

Instance Method Details

#filesObject

Return a list of all files in our fileset. This is different from the normal definition of find in that we support specific levels of recursion, which means we need to know when we’re going another level deep, which Find doesn’t do.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puppet/file_serving/fileset.rb', line 59

def files
  files = perform_recursion

  # Now strip off the leading path, so each file becomes relative, and remove
  # any slashes that might end up at the beginning of the path.
  result = files.collect { |file| file.sub(%r{^#{Regexp.escape(@path)}/*}, '') }

  # And add the path itself.
  result.unshift(".")

  result
end