Class: Ronin::PostEx::RemoteDir

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ronin/post_ex/remote_dir.rb

Overview

The RemoteDir class represents directories on a remote system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, entries = []) ⇒ RemoteDir

Creates a new Dir object.

Parameters:

  • path (String)

    The path to the directory.

  • entries (Array<String>) (defaults to: [])

    The entries of the directory.



47
48
49
50
51
52
# File 'lib/ronin/post_ex/remote_dir.rb', line 47

def initialize(path,entries=[])
  @path    = path
  @entries = entries
  @pos     = 0
  @closed  = false
end

Instance Attribute Details

#pathObject (readonly)

The path of the directory



31
32
33
# File 'lib/ronin/post_ex/remote_dir.rb', line 31

def path
  @path
end

#posInteger (readonly)

The current position in the open directory.

Returns:

  • (Integer)


36
37
38
# File 'lib/ronin/post_ex/remote_dir.rb', line 36

def pos
  @pos
end

Instance Method Details

#closeObject

Closes the opened directory.



173
174
175
176
# File 'lib/ronin/post_ex/remote_dir.rb', line 173

def close
  @closed = true
  return nil
end

#each {|entry| ... } ⇒ Enumerator

Iterates through the entries within the directory.

Yields:

  • (entry)

    The given block will be passed each entry.

Yield Parameters:

  • entry (String)

    An entry from the directory.

Returns:

  • (Enumerator)

    An enumerator will be returned if no block is given.

Raises:

  • (IOError)

    The directory is closed.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/ronin/post_ex/remote_dir.rb', line 130

def each
  return enum_for(__method__) unless block_given?

  if @closed
    raise(IOError,"closed directory")
  end

  @pos = 0

  @entries.each do |entry|
    yield entry
    @pos += 1
  end

  return self
end

#inspectString

Inspects the directory.

Returns:

  • (String)

    The inspected directory.



184
185
186
# File 'lib/ronin/post_ex/remote_dir.rb', line 184

def inspect
  "<#{self.class}:#{@path}>"
end

#readString?

Reads the next entry from the directory.

Returns:

  • (String, nil)

    The next entry from the opened directory. If all entries have been read, nil is returned.

Raises:

  • (IOError)

    The directory is closed.



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/ronin/post_ex/remote_dir.rb', line 157

def read
  if @closed
    raise(IOError,"closed directory")
  end

  if @pos < @entries.length
    next_entry = @entries[@pos]

    @pos += 1
    return next_entry
  end
end

#rewindDir

Rewinds the opened directory.

Returns:

  • (Dir)

Raises:

  • (IOError)

    The directory is closed.



79
80
81
82
83
84
85
86
# File 'lib/ronin/post_ex/remote_dir.rb', line 79

def rewind
  if @closed
    raise(IOError,"closed directory")
  end

  @pos = 0
  return self
end

#seek(new_pos) ⇒ Dir

Sets the position within the open directory.

Parameters:

  • new_pos (Integer)

    The new position within the open directory.

Returns:

  • (Dir)

Raises:

  • (Errno::EINVAL)

    The new position was out of bounds.

  • (IOError)

    The directory is closed.



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ronin/post_ex/remote_dir.rb', line 102

def seek(new_pos)
  if @closed
    raise(IOError,"closed directory")
  end

  if (new_pos < 0) || (new_pos >= @entries.length)
    raise(Errno::EINVAL,"invalid seek position")
  end

  @pos = new_pos
  return self
end

#tellInteger

Returns the position in the opened directory.

Returns:

  • (Integer)

    The position of the opened directory.

Raises:

  • (IOError)

    The directory is closed.



63
64
65
66
67
68
69
# File 'lib/ronin/post_ex/remote_dir.rb', line 63

def tell
  if @closed
    raise(IOError,"closed directory")
  end

  return @pos
end