Class: Inspec::Resources::FileSystemResource

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/filesystem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(partition) ⇒ FileSystemResource

Returns a new instance of FileSystemResource.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inspec/resources/filesystem.rb', line 25

def initialize(partition)
  @partition = partition
  @cache = nil
  # select file system manager
  @fsman = nil

  os = inspec.os
  if os.unix?
    @fsman = UnixFileSystemResource.new(inspec)
  elsif os.windows?
    @fsman = WindowsFileSystemResource.new(inspec)
  else
    raise Inspec::Exceptions::ResourceSkipped, "The `filesystem` resource is not supported on your OS yet."
  end
end

Instance Attribute Details

#partitionObject (readonly)

Returns the value of attribute partition.



23
24
25
# File 'lib/inspec/resources/filesystem.rb', line 23

def partition
  @partition
end

Instance Method Details

#free_kbObject



69
70
71
72
# File 'lib/inspec/resources/filesystem.rb', line 69

def free_kb
  info = @fsman.info(@partition)
  info[:free_kb]
end

#infoObject



41
42
43
44
45
46
# File 'lib/inspec/resources/filesystem.rb', line 41

def info
  return @cache unless @cache.nil?
  return {} if @fsman.nil?

  @cache = @fsman.info(@partition)
end

#nameObject



83
84
85
86
# File 'lib/inspec/resources/filesystem.rb', line 83

def name
  info = @fsman.info(@partition)
  info[:name]
end

#percent_freeObject



74
75
76
# File 'lib/inspec/resources/filesystem.rb', line 74

def percent_free
  100 * free_kb / size_kb
end

#resource_idObject



88
89
90
# File 'lib/inspec/resources/filesystem.rb', line 88

def resource_id
  partition
end

#sizeObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/inspec/resources/filesystem.rb', line 57

def size
  Inspec.deprecate(:property_filesystem_size, "The `size` property did not reliably use the correct units. Please use `size_kb` instead.")
  if inspec.os.windows?
    # On windows, we had a bug prior to #3767 in which the
    # 'size' value was be scaled to GB in powershell.
    # We now collect it in KB.
    (size_kb / (1024 * 1024)).to_i
  else
    size_kb
  end
end

#size_kbObject



52
53
54
55
# File 'lib/inspec/resources/filesystem.rb', line 52

def size_kb
  info = @fsman.info(@partition)
  info[:size_kb]
end

#to_sObject



48
49
50
# File 'lib/inspec/resources/filesystem.rb', line 48

def to_s
  "FileSystem #{@partition}"
end

#typeObject



78
79
80
81
# File 'lib/inspec/resources/filesystem.rb', line 78

def type
  info = @fsman.info(@partition)
  info[:type]
end