Module: Kanrisuru::Core::Mount

Extended by:
OsPackage::Define
Defined in:
lib/kanrisuru/core/mount.rb,
lib/kanrisuru/core/mount/commands.rb,
lib/kanrisuru/core/mount/commands/mount.rb,
lib/kanrisuru/core/mount/commands/umount.rb

Instance Method Summary collapse

Methods included from OsPackage::Define

extended, os_define

Instance Method Details

#mount(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/kanrisuru/core/mount/commands/mount.rb', line 6

def mount(opts = {})
  type = opts[:type]

  bind_old = opts[:bind_old]
  bind_new = opts[:bind_new]
  rbind_old = opts[:rbind_old]
  rbind_new = opts[:rbind_new]
  move_old = opts[:move_old]
  move_new = opts[:move_new]
  fs_opts   = opts[:fs_opts]

  command = Kanrisuru::Command.new('mount')

  if Kanrisuru::Util.present?(bind_old) && Kanrisuru::Util.present?(bind_new)
    command.append_flag('--bind')
    command << bind_old
    command << bind_new
  elsif Kanrisuru::Util.present?(rbind_old) && Kanrisuru::Util.present?(rbind_new)
    command.append_flag('--rbind')
    command << rbind_old
    command << rbind_new
  elsif Kanrisuru::Util.present?(move_old) && Kanrisuru::Util.present?(move_new)
    command.append_flag('--move')
    command << move_old
    command << move_new
  else
    command.append_arg('-L', opts[:label])
    command.append_arg('-U', opts[:uuid])
    command.append_flag('-f', opts[:fake])
    command.append_flag('-i', opts[:internal_only])
    command.append_flag('-s', opts[:sloppy])

    command.append_flag('--no-mtab', opts[:no_mtab])
    command.append_flag('--no-canonicalize', opts[:no_canonicalize])

    fs_options = nil
    if Kanrisuru::Util.present?(type)
      add_type(command, type)
      fs_options = Kanrisuru::Remote::Fstab::Options.new(type, fs_opts) if fs_opts
    elsif fs_opts
      fs_options = Kanrisuru::Remote::Fstab::Options.new('common', fs_opts)
    end

    if Kanrisuru::Util.present?(opts[:all])
      command.append_flag('-a')
      add_test_opts(command, opts[:test_opts], type)
    else
      command.append_arg('-o', fs_options.to_s)

      command << opts[:device] if Kanrisuru::Util.present?(opts[:device])
      command << opts[:directory] if Kanrisuru::Util.present?(opts[:directory])
    end
  end

  execute_shell(command)
  Kanrisuru::Result.new(command)
end

#umount(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kanrisuru/core/mount/commands/umount.rb', line 6

def umount(opts = {})
  all = opts[:all]
  type = opts[:type]
  command = Kanrisuru::Command.new('umount')

  command.append_flag('--fake', opts[:fake])
  command.append_flag('--no-canonicalize', opts[:no_canonicalize])
  command.append_flag('-n', opts[:no_mtab])
  command.append_flag('-r', opts[:fail_remount_readonly])
  command.append_flag('-d', opts[:free_loopback])

  command.append_flag('-l', opts[:lazy])
  command.append_flag('-f', opts[:force])

  command.append_flag('--all-targets', opts[:all_targets])
  command.append_flag('--recursive', opts[:recursive])

  if Kanrisuru::Util.present?(all)
    command.append_flag('-a')
    add_type(command, type)
    add_test_opts(command, opts[:test_opts], type)
  else
    command << opts[:device] if Kanrisuru::Util.present?(opts[:device])
    command << opts[:directory] if Kanrisuru::Util.present?(opts[:directory])
  end

  execute_shell(command)

  Kanrisuru::Result.new(command)
end