Class: Puppet::Util::FileType

Inherits:
Object
  • Object
show all
Extended by:
ClassGen
Includes:
SELinux
Defined in:
lib/vendor/puppet/util/filetype.rb

Constant Summary

Constants included from Puppet::Util

AbsolutePathPosix, AbsolutePathWindows

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassGen

genclass, genmodule, rmclass

Methods included from Puppet::Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from SELinux

#get_selinux_current_context, #get_selinux_default_context, #parse_selinux_context, #selinux_support?, #set_selinux_context, #set_selinux_default_context

Constructor Details

#initialize(path) ⇒ FileType

Returns a new instance of FileType.

Raises:

  • (ArgumentError)


77
78
79
80
# File 'lib/vendor/puppet/util/filetype.rb', line 77

def initialize(path)
  raise ArgumentError.new("Path is nil") if path.nil?
  @path = path
end

Class Attribute Details

.nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/vendor/puppet/util/filetype.rb', line 14

def name
  @name
end

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



9
10
11
# File 'lib/vendor/puppet/util/filetype.rb', line 9

def loaded
  @loaded
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/vendor/puppet/util/filetype.rb', line 9

def path
  @path
end

#syncedObject

Returns the value of attribute synced.



9
10
11
# File 'lib/vendor/puppet/util/filetype.rb', line 9

def synced
  @synced
end

Class Method Details

.filetype(type) ⇒ Object



68
69
70
# File 'lib/vendor/puppet/util/filetype.rb', line 68

def self.filetype(type)
  @filetypes[type]
end

.newfiletype(name, &block) ⇒ Object

Create a new filetype.



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
64
65
66
# File 'lib/vendor/puppet/util/filetype.rb', line 19

def self.newfiletype(name, &block)
  @filetypes ||= {}

  klass = genclass(
    name,
    :block => block,
    :prefix => "FileType",
    :hash => @filetypes
  )

  # Rename the read and write methods, so that we're sure they
  # maintain the stats.
  klass.class_eval do
    # Rename the read method
    define_method(:real_read, instance_method(:read))
    define_method(:read) do
      begin
        val = real_read
        @loaded = Time.now
        if val
          return val.gsub(/# HEADER.*\n/,'')
        else
          return ""
        end
      rescue Puppet::Error => detail
        raise
      rescue => detail
        puts detail.backtrace if Puppet[:trace]
        raise Puppet::Error, "#{self.class} could not read #{@path}: #{detail}"
      end
    end

    # And then the write method
    define_method(:real_write, instance_method(:write))
    define_method(:write) do |text|
      begin
        val = real_write(text)
        @synced = Time.now
        return val
      rescue Puppet::Error => detail
        raise
      rescue => detail
        puts detail.backtrace if Puppet[:debug]
        raise Puppet::Error, "#{self.class} could not write #{@path}: #{detail}"
      end
    end
  end
end

Instance Method Details

#bucketObject

Pick or create a filebucket to use.



73
74
75
# File 'lib/vendor/puppet/util/filetype.rb', line 73

def bucket
  @bucket ||= Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
end

#cronargsObject

Arguments that will be passed to the execute method. Will set the uid to the target user if the target user and the current user are not the same



85
86
87
88
89
90
91
# File 'lib/vendor/puppet/util/filetype.rb', line 85

def cronargs
  if uid = Puppet::Util.uid(@path) and uid == Puppet::Util::SUIDManager.uid
    {:failonfail => true, :combine => true}
  else
    {:failonfail => true, :combine => true, :uid => @path}
  end
end