lib/utils/parser.rb
def parse_mount_options(mount_line, compatibility = false)
    if includes_whitespaces?(mount_line)
      # Device-/Sharenames and Mountpoints including whitespaces require special treatment:
      # We use the keyword ' type ' to split up and rebuild the desired array of fields
      type_split = mount_line.split(' type ')
      fs_path = type_split[0]
      other_opts = type_split[1]
      fs, path = fs_path.match(%r{^(.+?)\son\s(/.+?)$}).captures
      mount = [fs, 'on', path, 'type']
      mount.concat(other_opts.scan(/\S+/))
    else
      # ... otherwise we just split the fields by whitespaces
      mount = mount_line.scan(/\S+/)
    end

    # parse device and type
    mount_options    = { device: mount[0], type: mount[4] }

    if compatibility == false
      # parse options as array
      mount_options[:options] = mount[5].gsub(/\(|\)/, '').split(',')
    else
      Inspec.deprecate(:mount_parser_serverspec_compat, 'Parsing mount options in this fashion is deprecated')
      mount_options[:options] = {}
      mount[5].gsub(/\(|\)/, '').split(',').each do |option|
        name, val = option.split('=')
        if val.nil?
          val = true
        elsif val =~ /^\d+$/
          # parse numbers
          val = val.to_i
        end
        mount_options[:options][name.to_sym] = val
      end
    end

    mount_options
  end
# this parses the output of mount command (only tested on linux)
# this method expects only one line of the mount output
this parses the output of mount command (only tested on linux)
this method expects only one line of the mount output
this parses the output of mount command ( only tested on linux ) this method expects only one line of the mount output
def parse_mount_options(mount_line, compatibility = false)
    if includes_whitespaces?(mount_line)
      type_split = mount_line.split(' type ')
      fs_path = type_split[0]
      other_opts = type_split[1]
      fs, path = fs_path.match(%r{^(.+?)\son\s(/.+?)$}).captures
      mount = [fs, 'on', path, 'type']
      mount.concat(other_opts.scan(/\S+/))
    else
      mount = mount_line.scan(/\S+/)
    end
    mount_options    = { device: mount[0], type: mount[4] }
    if compatibility == false
      mount_options[:options] = mount[5].gsub(/\(|\)/, '').split(',')
    else
      Inspec.deprecate(:mount_parser_serverspec_compat, 'Parsing mount options in this fashion is deprecated')
      mount_options[:options] = {}
      mount[5].gsub(/\(|\)/, '').split(',').each do |option|
        name, val = option.split('=')
        if val.nil?
          val = true
        elsif val =~ /^\d+$/
          val = val.to_i
        end
        mount_options[:options][name.to_sym] = val
      end
    end
    mount_options
  end
def parse_mount_options ( mount_line , compatibility = false ) if includes_whitespaces? ( mount_line ) type_split = mount_line . split ( ' type ' ) fs_path = type_split [ 0 ] other_opts = type_split [ 1 ] fs , path = fs_path . match ( %r{ ^(.+?) \s on \s (/.+?)$ } ) . captures mount = [ fs , 'on' , path , 'type' ] mount . concat ( other_opts . scan ( / \S + / ) ) else mount = mount_line . scan ( / \S + / ) end mount_options = { device : mount [ 0 ] , type : mount [ 4 ] } if compatibility == false mount_options [ :options ] = mount [ 5 ] . gsub ( / \( | \) / , '' ) . split ( ',' ) else Inspec . deprecate ( :mount_parser_serverspec_compat , 'Parsing mount options in this fashion is deprecated' ) mount_options [ :options ] = { } mount [ 5 ] . gsub ( / \( | \) / , '' ) . split ( ',' ) . each do | option | name , val = option . split ( '=' ) if val . nil? val = true elsif val =~ / ^ \d +$ / val = val . to_i end mount_options [ :options ] [ name . to_sym ] = val end end mount_options end
this parses the output of mount command (only tested on linux)
this method expects only one line of the mount output
this parses the output of mount command ( only tested on linux ) this method expects only one line of the mount output
# Device-/Sharenames and Mountpoints including whitespaces require special treatment: # We use the keyword ' type ' to split up and rebuild the desired array of fields # ... otherwise we just split the fields by whitespaces # parse device and type # parse options as array # parse numbers
mount_line
compatibility