Class: OsCtld::Assets::BaseFile
- Inherits:
-
Base
- Object
- Base
- OsCtld::Assets::BaseFile
show all
- Defined in:
- lib/osctld/assets/base_file.rb
Instance Attribute Summary
Attributes inherited from Base
#errors, #opts, #path
Instance Method Summary
collapse
Methods inherited from Base
#add_error, #prefetch_zfs, register, #run_validation, #state, #type, #valid?, #validate?, #validate_block
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) 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
53
54
55
56
|
# File 'lib/osctld/assets/base_file.rb', line 53
def mode
stat.mode & 0o7777
end
|
#stat ⇒ Object
49
50
51
|
# File 'lib/osctld/assets/base_file.rb', line 49
def stat
@stat ||= File.stat(path)
end
|
#validate(run) ⇒ Object
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
|