Class: OsCtld::Assets::BaseFile
- Inherits:
-
Assets::Base
- Object
- Assets::Base
- OsCtld::Assets::BaseFile
- Defined in:
- lib/osctld/assets/base_file.rb
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(path, opts) ⇒ BaseFile
constructor
A new instance of BaseFile.
- #mode ⇒ Object protected
- #stat ⇒ Object protected
- #validate(run) ⇒ Object protected
Constructor Details
#initialize(path, opts) ⇒ BaseFile
Returns a new instance of BaseFile.
13 14 15 |
# File 'lib/osctld/assets/base_file.rb', line 13 def initialize(path, opts) # rubocop:disable all super end |
Instance Method Details
#exist? ⇒ Boolean
17 18 19 |
# File 'lib/osctld/assets/base_file.rb', line 17 def exist? File.exist?(path) end |
#mode ⇒ Object (protected)
53 54 55 56 |
# File 'lib/osctld/assets/base_file.rb', line 53 def mode # Extract permission bits, see man inode(7) stat.mode & 0o7777 end |
#stat ⇒ Object (protected)
49 50 51 |
# File 'lib/osctld/assets/base_file.rb', line 49 def stat @stat ||= File.stat(path) end |
#validate(run) ⇒ Object (protected)
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 |
# File 'lib/osctld/assets/base_file.rb', line 23 def validate(run) return if !exist? && opts[:optional] begin if opts[:user] && stat.uid != opts[:user] add_error("invalid owner: expected #{opts[:user]}, got #{stat.uid}") end if opts[:group] && stat.gid != opts[:group] add_error("invalid group: expected #{opts[:group]}, got #{stat.gid}") end if opts[:mode] && mode != opts[:mode] add_error("invalid mode: expected #{opts[:mode].to_s(8)}, got #{mode.to_s(8)}") end if opts[:mode_bit_and] && (mode & opts[:mode_bit_and]) != opts[:mode_bit_and] add_error("invalid mode: bitwise and with #{opts[:mode_bit_and].to_s(8)} does not match") end rescue Errno::ENOENT add_error('does not exist') end super end |