Class: Yast::NfsOptionsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/NfsOptions.rb

Constant Summary

NEGATABLE_OPTIONS =

these can be negated by “no”

[
  "ac",
  "acl",
  "atime",
  "auto",
  "bg",
  "cto",
  "dev",
  "diratime",
  "exec",
  "fg",
  "fsc",
  "group",
  "hard",
  "intr",
  "iversion",
  "lock",
  "mand",
  "owner",
  "posix",
  "rdirplus",
  "relatime",
  "soft",
  "strictatime",
  "suid",
  "tcp",
  "udp",
  "user",
  "users"
]
NEGATED_OPTIONS =
NEGATABLE_OPTIONS.map{ |o| "no#{o}" }
SIMPLE_OPTIONS =

these cannot be negated they are not nfs specific BTW

[
  "_netdev",
  "async",
  "bind",
  "defaults",
  "dirsync",
  "loud",
  "nofail",
  "owner",
  "rbind",
  "remount",
  "ro",
  "rw",
  "silent",
  "sync"
]
OPTIONS_WITH_VALUE =
[
  "acdirmax",
  "acdirmin",
  "acdirmin",
  "acregmax",
  "acregmin",
  "actimeo",
  "bsize",
  "clientaddr",
  "context",
  "defcontext",
  "fscontext",
  "minorversion",
  "mounthost",
  "mountport",
  "mountprog",
  "mountvers",
  "namlen",
  "nfsprog",
  "nfsvers",
  "port",
  "proto",
  "retrans",
  "retry",
  "rootcontext",
  "rsize",
  "sec",
  "timeo",
  "vers",
  "wsize"
]

Instance Method Summary (collapse)

Instance Method Details

- (Array) from_string(options)

Parse to an internal representation: Simply split by commas, but “defaults” is represented by the empty list

Parameters:

  • options (String)

    a fstab option string

Returns:

  • (Array)

    of individual options



113
114
115
116
117
# File '../../src/modules/NfsOptions.rb', line 113

def from_string(options)
  return [] if options == "defaults"

  options.split(",")
end

- (Object) get_nfs41(options)

FIXME: factor out get_nfs4(vfstype, options) (depending on n::o)! * @param options fstab option string * @return is version >= 4.1 enabled



175
176
177
178
179
180
# File '../../src/modules/NfsOptions.rb', line 175

def get_nfs41(options)
  option_list = from_string(options)

  _ENABLED = "minorversion=1"
  Builtins.contains(option_list, _ENABLED)
end

- (Object) main



105
106
107
# File '../../src/modules/NfsOptions.rb', line 105

def main
  textdomain "nfs"
end

- (Boolean) non_value_option?(option)

Returns:

  • (Boolean)


128
129
130
# File '../../src/modules/NfsOptions.rb', line 128

def non_value_option?(option)
  NEGATABLE_OPTIONS.include?(option) || NEGATED_OPTIONS.include?(option) || SIMPLE_OPTIONS.include?(option)
end

- (Object) set_nfs41(options, nfs41)

Add or remove minorversion=1 according to nfs41. FIXME vfstype=nfs4 is deprecated in favor of nfsvers=4 (aka vers=4)

Parameters:

  • options (String)

    fstab option string

  • nfs41 (Boolean)

    is version >= 4.1 enabled

Returns:

  • new fstab option string



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File '../../src/modules/NfsOptions.rb', line 187

def set_nfs41(options, nfs41)
  # don't mutate the string unnecessarily
  return options if get_nfs41(options) == nfs41

  _ENABLED = "minorversion=1"
  _DISABLED = "minorversion=0"

  option_list = from_string(options)
  option_list = Builtins.filter(option_list) { |opt| opt != _ENABLED }
  option_list = Builtins.filter(option_list) { |opt| opt != _DISABLED }

  option_list = Builtins.add(option_list, _ENABLED) if nfs41

  to_string(option_list)
end

- (Object) to_string(option_list)

Convert list of individual options to a fstab option string

Parameters:

  • option_list (Array<String>)

    list of individual options

Returns:

  • a fstab option string



122
123
124
125
126
# File '../../src/modules/NfsOptions.rb', line 122

def to_string(option_list)
  return "defaults" if option_list.empty?

  option_list.join(",")
end

- (Object) validate(options)

Checks the nfs options for /etc/fstab: nonempty, comma separated list of foo,nofoo,bar=baz (see nfs(5))

Parameters:

  • options (String)

    options

Returns:

  • a translated string with error message, emtpy string if ok



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File '../../src/modules/NfsOptions.rb', line 136

def validate(options)
  # To translators: error popup
  if options.empty?
    return _("Empty option strings are not allowed.")
  end

  error_message = ""

  from_string(options).each do |opt|
    key, value, *rest = opt.split("=")

    # Known options without any expected value
    if non_value_option?(key)
      next if value.nil?
      # To translators: error popup
      error_message = _("Unexpected value '#{value}' for option '#{key}'") % { :value => value, :key => key }
    # All unknown options
    elsif ! OPTIONS_WITH_VALUE.include?(key)
      # To translators: error popup
      error_message = _("Unknown option: '%{key}'") % { :key => key }
    # All known ones with badly specified values
    elsif !rest.empty?
      # To translators: error popup
      error_message = _("Invalid option: '%{opt}'") % { :opt => opt }
    # All options missing a value
    elsif value.nil?
      # To translators: error popup
      error_message = _("Empty value for option: '%{key}'") % { :key => key }
    end

    break unless error_message.empty?
  end

  error_message
end