Class: Yobi::MountHandle

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

Overview

A live Restic mount process, returned by Yobi::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:, pipe:, output:, argv:) ⇒ MountHandle

:nodoc:

Parameters:

  • wait_thr: (Process::Waiter)
  • mountpoint: (String)
  • pipe: (IO)
  • output: (ResticOutput)
  • argv: (Array[String])


12
13
14
15
16
17
18
19
# File 'lib/yobi/mount_handle.rb', line 12

def initialize(wait_thr:, mountpoint:, pipe:, output:, argv:) # :nodoc:
  @wait_thr = wait_thr
  @mountpoint = mountpoint
  @pipe = pipe
  @output = output
  @argv = argv
  @stopped = false
end

Instance Attribute Details

#mountpointString (readonly)

The path the repository is mounted at.

Returns:

  • (String)


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

def mountpoint
  @mountpoint
end

Instance Method Details

#inspectObject



31
32
33
# File 'lib/yobi/mount_handle.rb', line 31

def inspect
  "#<#{self.class} pid=#{pid} mountpoint=#{mountpoint.inspect} stopped=#{stopped?}>"
end

#pidInteger

The Restic process's pid.

Returns:

  • (Integer)


22
23
24
# File 'lib/yobi/mount_handle.rb', line 22

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+).



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yobi/mount_handle.rb', line 39

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: @output, argv: @argv)
end

#stopped?Boolean

true once #stop has run.

Returns:

  • (Boolean)


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

def stopped?
  @stopped
end