Class: VirtFS::ThinDirDelegator

Inherits:
Object
  • Object
show all
Defined in:
lib/virtfs/thin_dir_delegator.rb

Overview

Dispatches Dir calls to/from VirtFS and the ‘Thin’ subsystem

Instance Method Summary collapse

Constructor Details

#initialize(fs_dir_obj, creation_path, fs_path, _hash_args) ⇒ ThinDirDelegator

Instance methods



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/virtfs/thin_dir_delegator.rb', line 6

def initialize(fs_dir_obj, creation_path, fs_path, _hash_args)
  @fs_dir_obj        = fs_dir_obj
  @creation_path     = creation_path
  @full_path         = VfsRealFile.join(fs_dir_obj.fs.mount_point, fs_path)
  @fs_path           = fs_path
  @dir_closed        = false
  @raw_pos           = 0 # FS-specific position
  @cur_tell          = -1
  @next_tell         = 0
  @tells             = []
  @raw_pos_to_tell   = {}
end

Instance Method Details

#closeObject

Raises:

  • (IOError)


19
20
21
22
23
24
# File 'lib/virtfs/thin_dir_delegator.rb', line 19

def close
  raise IOError, "closed directory" if @dir_closed
  @fs_dir_obj.close
  @dir_closed = true
  nil
end

#eachObject

Raises:

  • (IOError)


26
27
28
29
30
31
32
33
# File 'lib/virtfs/thin_dir_delegator.rb', line 26

def each
  return to_enum(__method__) unless block_given?
  raise IOError, "closed directory" if @dir_closed
  while (file_name = read)
    yield(file_name)
  end
  self
end

#pathObject Also known as: to_path



35
36
37
# File 'lib/virtfs/thin_dir_delegator.rb', line 35

def path
  @creation_path
end

#pos=(tell_val) ⇒ Object

Raises:

  • (IOError)


40
41
42
43
44
# File 'lib/virtfs/thin_dir_delegator.rb', line 40

def pos=(tell_val)
  raise IOError, "closed directory" if @dir_closed
  seek(tell_val)
  tell_val
end

#readObject

Raises:

  • (IOError)


46
47
48
49
50
# File 'lib/virtfs/thin_dir_delegator.rb', line 46

def read
  raise IOError, "closed directory" if @dir_closed
  file_name, @raw_pos = @fs_dir_obj.read(@raw_pos)
  file_name
end

#rewindObject

Raises:

  • (IOError)


52
53
54
55
56
# File 'lib/virtfs/thin_dir_delegator.rb', line 52

def rewind
  raise IOError, "closed directory" if @dir_closed
  @raw_pos = 0
  self
end

#seek(tell_val) ⇒ Object

Raises:

  • (IOError)


58
59
60
61
62
63
64
# File 'lib/virtfs/thin_dir_delegator.rb', line 58

def seek(tell_val)
  raise IOError, "closed directory" if @dir_closed
  return self unless (new_pos = @tells[tell_val])
  @cur_tell = tell_val
  @raw_pos = new_pos
  self
end

#tellObject Also known as: pos

Raises:

  • (IOError)


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/virtfs/thin_dir_delegator.rb', line 66

def tell
  raise IOError, "closed directory" if @dir_closed
  if (tell_val = @raw_pos_to_tell[@raw_pos])
    return @cur_tell = tell_val
  end
  @cur_tell = @next_tell
  @tells[@cur_tell] = @raw_pos
  @raw_pos_to_tell[@raw_pos] = @cur_tell
  @next_tell += 1
  @cur_tell
end