Class: FFI::Libfuse::Adapter::Ruby::ReaddirFiller
- Inherits:
-
Object
- Object
- FFI::Libfuse::Adapter::Ruby::ReaddirFiller
- Defined in:
- lib/ffi/libfuse/adapter/ruby.rb
Overview
Helper class for FuseOperations#readdir
Instance Method Summary collapse
-
#fill(name, stat: nil, offset: 0, fill_dir_plus: false) ⇒ Boolean
True if the buffer accepted the entry.
-
#initialize(buf, filler, fuse3: FUSE_MAJOR_VERSION >= 3) ⇒ ReaddirFiller
constructor
A new instance of ReaddirFiller.
-
#readdir_fh(dir_handle, offset = 0) ⇒ Object
Fill readdir from a directory handle.
-
#to_proc ⇒ Proc
A proc to pass to something that yields like ##fill.
Constructor Details
#initialize(buf, filler, fuse3: FUSE_MAJOR_VERSION >= 3) ⇒ ReaddirFiller
Returns a new instance of ReaddirFiller.
44 45 46 47 48 49 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 44 def initialize(buf, filler, fuse3: FUSE_MAJOR_VERSION >= 3) @buf = buf @filler = filler @stat_buf = nil @fuse3 = fuse3 end |
Instance Method Details
#fill(name, stat: nil, offset: 0, fill_dir_plus: false) ⇒ Boolean
Returns true if the buffer accepted the entry.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 72 def fill(name, stat: nil, offset: 0, fill_dir_plus: false) raise StopIteration unless @buf fill_flags = fill_flags(fill_dir_plus: fill_dir_plus) fill_stat = fill_stat(stat) return true if @filler.call(@buf, name, fill_stat, offset, *fill_flags).zero? @buf = nil false end |
#readdir_fh(dir_handle, offset = 0) ⇒ Object
Fill readdir from a directory handle
55 56 57 58 59 60 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 55 def readdir_fh(dir_handle, offset = 0) raise Errno::ENOTSUP unless %i[seek read tell].all? { |m| dir_handle.respond_to?(m) } dir_handle.seek(offset) loop while (name = dir_handle.read) && fill(name, offset: dir_handle.tell) end |
#to_proc ⇒ Proc
Returns a proc to pass to something that yields like ##fill.
84 85 86 87 88 |
# File 'lib/ffi/libfuse/adapter/ruby.rb', line 84 def to_proc proc do |name, stat: nil, offset: 0, fill_dir_plus: false| fill(name, stat: stat, offset: offset, fill_dir_plus: fill_dir_plus) end end |