Sha256: 0d9eb3ea6ff4964e7382d3f45941a05689583e25f7342c8a0b8997806d050652

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module FFI
  module Libfuse
    module Filesystem
      module Ruby
        # Filesystem methods representing a symbolic link
        # Satisfies the contract of {Adapter::Ruby}
        module VirtualLink
          attr_accessor :target

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

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

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

            @target = from_path
            init_node(0o777)
          end

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

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

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

            accounting&.adjust(0, -1)
          end

          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
        end
      end

      # A Filesystem that represents a single symbolic link at the root
      class VirtualLink
        prepend Adapter::Ruby::Prepend
        include Fuse2Compat
        include Ruby::VirtualLink
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-libfuse-0.4.1 lib/ffi/libfuse/filesystem/virtual_link.rb