Class: OsCtld::Assets::Dataset

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/assets/dataset.rb

Instance Attribute Summary

Attributes inherited from Base

#errors, #opts, #path

Instance Method Summary collapse

Methods inherited from Base

#add_error, register, #state, type, #type, #validate, #validate?

Constructor Details

#initialize(path, opts) ⇒ Dataset

Returns a new instance of Dataset

Parameters:

  • opts (Hash)

    options

Options Hash (opts):

  • uidmap (Array, nil)
  • gidmap (Array, nil)
  • user (Integer, nil)
  • group (Integer, nil)
  • mode (Integer, nil)


17
18
19
# File 'lib/osctld/assets/dataset.rb', line 17

def initialize(path, opts)
  super
end

Instance Method Details

#make_ugid_map(arr) ⇒ Object (protected)



77
78
79
80
81
# File 'lib/osctld/assets/dataset.rb', line 77

def make_ugid_map(arr)
  arr.map do |entry|
    entry.join(':')
  end.join(',')
end

#modeObject (protected)



72
73
74
75
# File 'lib/osctld/assets/dataset.rb', line 72

def mode
  # Extract permission bits, see man inode(7)
  stat.mode & 07777
end

#statObject (protected)



68
69
70
# File 'lib/osctld/assets/dataset.rb', line 68

def stat
  @stat ||= File.stat(@mountpoint)
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/osctld/assets/dataset.rb', line 21

def valid?
  ret = zfs(
    :get,
    '-H -ovalue mountpoint,uidmap,gidmap',
    path,
    valid_rcs: [1]
  )

  if ret.error?
    add_error('does not exist')
    return super
  end

  @mountpoint, uidmap, gidmap = ret.output.split("\n")

  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 #{state.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[:uidmap]
    expected_uidmap = make_ugid_map(opts[:uidmap])

    if expected_uidmap != uidmap
      add_error("invalid uidmap: expected #{expected_uidmap}, got #{uidmap}")
    end
  end

  if opts[:gidmap]
    expected_gidmap = make_ugid_map(opts[:gidmap])

    if expected_gidmap != gidmap
      add_error("invalid gidmap: expected #{expected_gidmap}, got #{gidmap}")
    end
  end

  super
end