Module: FFI::Libfuse::Filesystem::Ruby::VirtualLink

Includes:
VirtualNode
Included in:
VirtualLink
Defined in:
lib/ffi/libfuse/filesystem/virtual_link.rb

Overview

Filesystem methods representing a symbolic link Satisfies the contract of Adapter::Ruby

Instance Attribute Summary collapse

Attributes included from VirtualNode

#accounting, #virtual_stat, #virtual_xattr

Instance Method Summary collapse

Methods included from VirtualNode

#chmod, #chown, #getxattr, #init_node, #listxattr, #statfs, #utimens

Instance Attribute Details

#targetObject

Returns the value of attribute target.



10
11
12
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 10

def target
  @target
end

Instance Method Details

#getattr(path, stat = nil, _ffi = nil) ⇒ Object

Raises:

  • (Errno::ENOENT)


42
43
44
45
46
47
48
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 42

def getattr(path, stat = nil, _ffi = nil)
  # We don't exist until create or otherwise or virtual stat exists
  raise Errno::ENOENT unless root?(path) && virtual_stat

  stat&.symlink(size: @target.length + 1, **virtual_stat)
  self
end

#initialize(accounting: nil) ⇒ Object



13
14
15
16
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 13

def initialize(accounting: nil)
  @target = target
  super
end

Raises:

  • (Errno::ENOENT)


29
30
31
32
33
34
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 29

def link(_from_path, path)
  raise Errno::ENOENT unless root?(path)

  # Cannot hard link a symbolic link
  raise Errno::EPERM
end


18
19
20
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 18

def readlink(_path, size)
  @target[0, size - 1] # buffer size needs null terminator
end

Raises:

  • (Errno::ENOENT)


22
23
24
25
26
27
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 22

def symlink(from_path, path)
  raise Errno::ENOENT unless root?(path)

  @target = from_path
  init_node(0o777)
end

Raises:

  • (Errno::ENOENT)


36
37
38
39
40
# File 'lib/ffi/libfuse/filesystem/virtual_link.rb', line 36

def unlink(path)
  raise Errno::ENOENT unless root?(path)

  accounting&.adjust(0, -1)
end