Module: Keybase::Local::KBFS

Defined in:
lib/keybase/local/kbfs.rb

Overview

Represents an interface to KBFS.

Constant Summary collapse

KBFS_STATUS_FILE =
Note:

The presence of this file is used to determine whether or not the mountpoint is actually KBFS or just a directory (since an accidental directory at the mountpoint is unlikely to contain this file).

The path to a hidden status file on KBFS.

File.join Config::KBFS_MOUNT, ".kbfs_status"

Class Method Summary collapse

Class Method Details

.functional?Boolean

Note:

The criteria for being "functional" is as follows:

  1. Keybase is running
  2. KBFS is running
  3. Config::KBFS_MOUNT is mounted

Returns whether or not KBFS is currently fully functional.

Returns:

  • (Boolean)

    whether or not KBFS is currently fully functional


44
45
46
# File 'lib/keybase/local/kbfs.rb', line 44

def functional?
  Local.running? && running? && mounted?
end

.mounted?Boolean

Note:

mounted? does not mean that KBFS is fully functional. For that, see functional?

Returns whether or not KBFS is currently mounted.

Returns:

  • (Boolean)

    whether or not KBFS is currently mounted


35
36
37
# File 'lib/keybase/local/kbfs.rb', line 35

def mounted?
  Sys::Filesystem.mounts.any? { |m| m.mount_point == Config::KBFS_MOUNT }
end

.running?Boolean

Note:

running? does not mean that KBFS is mounted. For that, see mounted?

Returns whether or not KBFS is currently running.

Returns:

  • (Boolean)

    whether or not KBFS is currently running


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/keybase/local/kbfs.rb', line 20

def running?
  if Gem.win_platform?
    !`tasklist | find "kbfsfuse.exe"`.empty?
  elsif RUBY_PLATFORM =~ /darwin/
    !`pgrep kbfs`.empty?
  else
    Dir["/proc/[0-9]*/comm"].any? do |comm|
      File.read(comm).chomp == "kbfsfuse" rescue false
    end
  end
end

.statusOpenStruct

Returns a struct mapping of the contents of KBFS_STATUS_FILE.

Returns:

Raises:


50
51
52
53
# File 'lib/keybase/local/kbfs.rb', line 50

def status
  raise Exceptions::KBFSNotRunningError unless functional?
  JSON.parse File.read(KBFS_STATUS_FILE), object_class: OpenStruct
end