Class: Puppet::Util::FileType Private
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.
Defined Under Namespace
Classes: FileReadError
Constant Summary
Constants included from Puppet::Util
ALNUM, ALPHA, AbsolutePathPosix, AbsolutePathWindows, DEFAULT_POSIX_MODE, DEFAULT_WINDOWS_MODE, ESCAPED, HEX, HttpProxy, PUPPET_STACK_INSERTION_FRAME, RESERVED, RFC_3986_URI_REGEX, UNRESERVED, UNSAFE
Constants included from POSIX
POSIX::LOCALE_ENV_VARS, POSIX::USER_ENV_VARS
Constants included from SymbolicFileMode
SymbolicFileMode::SetGIDBit, SymbolicFileMode::SetUIDBit, SymbolicFileMode::StickyBit, SymbolicFileMode::SymbolicMode, SymbolicFileMode::SymbolicSpecialToBit
Constants included from SELinux
SELinux::S_IFDIR, SELinux::S_IFLNK, SELinux::S_IFREG
Class Attribute Summary collapse
- .name ⇒ Object private
Instance Attribute Summary collapse
- #loaded ⇒ Object private
- #path ⇒ Object private
- #synced ⇒ Object private
Class Method Summary collapse
- .filetype(type) ⇒ Object private
-
.newfiletype(name, &block) ⇒ Object
private
Create a new filetype.
Instance Method Summary collapse
-
#bucket ⇒ Object
private
Pick or create a filebucket to use.
-
#cronargs ⇒ Object
private
Arguments that will be passed to the execute method.
-
#initialize(path, default_mode = nil) ⇒ FileType
constructor
private
A new instance of FileType.
Methods included from ClassGen
Methods included from Puppet::Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from SELinux
#get_selinux_current_context, #get_selinux_default_context, #parse_selinux_context, #selinux_category_to_label, #selinux_support?, selinux_support?, #set_selinux_context, #set_selinux_default_context
Constructor Details
#initialize(path, default_mode = nil) ⇒ FileType
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.
Returns a new instance of FileType.
81 82 83 84 85 |
# File 'lib/puppet/util/filetype.rb', line 81 def initialize(path, default_mode = nil) raise ArgumentError.new(_("Path is nil")) if path.nil? @path = path @default_mode = default_mode end |
Class Attribute Details
.name ⇒ 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.
16 17 18 |
# File 'lib/puppet/util/filetype.rb', line 16 def name @name end |
Instance Attribute Details
#loaded ⇒ 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.
9 10 11 |
# File 'lib/puppet/util/filetype.rb', line 9 def loaded @loaded end |
#path ⇒ 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.
9 10 11 |
# File 'lib/puppet/util/filetype.rb', line 9 def path @path end |
#synced ⇒ 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.
9 10 11 |
# File 'lib/puppet/util/filetype.rb', line 9 def synced @synced end |
Class Method Details
.filetype(type) ⇒ 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.
72 73 74 |
# File 'lib/puppet/util/filetype.rb', line 72 def self.filetype(type) @filetypes[type] end |
.newfiletype(name, &block) ⇒ 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.
Create a new filetype.
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 67 68 69 70 |
# File 'lib/puppet/util/filetype.rb', line 21 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 raise rescue => detail = _("%{klass} could not read %{path}: %{detail}") % { klass: self.class, path: @path, detail: detail } Puppet.log_exception(detail, ) raise Puppet::Error, , detail.backtrace 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 raise rescue => detail = _("%{klass} could not write %{path}: %{detail}") % { klass: self.class, path: @path, detail: detail } Puppet.log_exception(detail, ) raise Puppet::Error, , detail.backtrace end end end end |
Instance Method Details
#bucket ⇒ 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.
Pick or create a filebucket to use.
77 78 79 |
# File 'lib/puppet/util/filetype.rb', line 77 def bucket @bucket ||= Puppet::Type.type(:filebucket).mkdefaultbucket.bucket end |
#cronargs ⇒ 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.
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
90 91 92 93 94 95 96 97 |
# File 'lib/puppet/util/filetype.rb', line 90 def cronargs uid = Puppet::Util.uid(@path) if uid && uid == Puppet::Util::SUIDManager.uid {:failonfail => true, :combine => true} else {:failonfail => true, :combine => true, :uid => @path} end end |