Merge pull request #603 from chef/dr/file-uid-gid

add file uid and gid accessors
This commit is contained in:
Christoph Hartmann 2016-03-31 09:52:35 +01:00
commit 2b2a9793a6

View file

@ -4,6 +4,8 @@
# author: Christoph Hartmann
# license: All rights reserved
require 'shellwords'
module Inspec::Resources
class FileResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
name 'file'
@ -89,6 +91,20 @@ module Inspec::Resources
end
end
# TODO: This is temporary and must be moved to train
def uid
res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
return nil if res.exit_status != 0 || res.stdout.empty?
res.stdout.to_i
end
# TODO: This is temporary and must be moved to train
def gid
res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
return nil if res.exit_status != 0 || res.stdout.empty?
res.stdout.to_i
end
def to_s
"File #{path}"
end