Class: Yobi::Mount

Inherits:
Object
  • Object
show all
Defined in:
lib/yobi/mount.rb,
sig/yobi.rbs

Overview

A live Restic mount process, returned by Restic#run_mount once Restic has reported itself ready. The mounted filesystem itself is browsed with ordinary file I/O at #mountpoint; this object only manages the Restic process's lifetime.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wait_thr:, mountpoint:, output:, output_file:, argv:) ⇒ Mount

Returns a new instance of Mount.

Parameters:

  • wait_thr (Process::Waiter)

    as returned by Open3.popen2e

  • mountpoint (String)
  • output (IO)
  • output_file (File)
  • argv (Array<String>)
  • wait_thr: (Process::Waiter)
  • mountpoint: (String)
  • output: (IO)
  • output_file: (File)
  • argv: (Array[String])


17
18
19
20
21
22
23
24
# File 'lib/yobi/mount.rb', line 17

def initialize(wait_thr:, mountpoint:, output:, output_file:, argv:)
  @wait_thr = wait_thr
  @mountpoint = mountpoint
  @output = output
  @output_file = output_file
  @argv = argv
  @stopped = false
end

Instance Attribute Details

#mountpointString (readonly)

Returns the path the repository is mounted at.

Returns:

  • (String)

    the path the repository is mounted at



10
11
12
# File 'lib/yobi/mount.rb', line 10

def mountpoint
  @mountpoint
end

Instance Method Details

#pidInteger

Returns the Restic process's pid.

Returns:

  • (Integer)

    the Restic process's pid



27
28
29
# File 'lib/yobi/mount.rb', line 27

def pid
  @wait_thr.pid
end

#stopvoid

This method returns an undefined value.

Sends the Restic process SIGINT, waits for it to unmount and exit, then raises based on its exit code. Safe to call more than once, and safe to call after the mount has already been stopped externally (e.g. via kill -INT or the OS's own umount/fusermount).



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/yobi/mount.rb', line 42

def stop
  return if @stopped

  @stopped = true

  begin
    Process.kill("INT", pid)
  rescue Errno::ESRCH
    nil
  end

  drain_remaining_output
  status = @wait_thr.value
  Restic.dispatch(exit_code: status.exitstatus, output: Yobi::ResticOutput.new(@output_file), argv: @argv)
end

#stopped?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/yobi/mount.rb', line 32

def stopped?
  @stopped
end