Class: Ronin::PostEx::RemoteFile::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/post_ex/remote_file/stat.rb

Overview

Represents the status information of a remote file. The Stat class using the fs_stat or file_stat method defined by the API object to request the remote status information.

Supported API Methods

  • file_stat(fd : Integer) -> Hash[Symbol, Object] | nil
  • fs_stat(path : String) -> Hash[Symbol, Object] | nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, path: nil, fd: nil) ⇒ Stat

Note:

This method requires session define the fs_stat API method.

Creates a new File Stat object.

Parameters:

  • session (Sessions::Session#fs_statt)

    The object controlling file-system stat.

  • path (String) (defaults to: nil)

    The path to stat.

  • fd (Integer) (defaults to: nil)

    The file description to stat.

Raises:

  • (ArgumentError)

    Neither the path: or fd: keyword arguments were given.

  • (NotImplementedError)

    The leveraging object does not define fs_stat or file_stat needed by Ronin::PostEx::RemoteFile::Stat.

  • (Errno::ENOENT)

    The remote file does not exist.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 123

def initialize(session, path: nil, fd: nil)
  if path
    unless session.respond_to?(:fs_stat)
      raise(NotImplementedError,"#{session.inspect} does not define #fs_stat")
    end
  elsif fd
    unless session.respond_to?(:file_stat)
      raise(NotImplementedError,"#{session.inspect} does not define #file_stat")
    end
  else
    raise(ArgumentError,"#{self.class}#initialize must be given either the path: or fd: keyword argument")
  end

  @session = session
  @path    = path.to_s

  unless (stat = @session.fs_stat(@path))
    raise(Errno::ENOENT,"No such file or directory #{@path.dump}")
  end

  @size      = stat[:size]
  @blocks    = stat[:blocks]
  @blocksize = stat[:blocksize]
  @inode     = stat[:inode]
  @nlinks    = stat[:nlinks]

  @mode = stat[:mode]
  @uid  = stat[:uid]
  @gid  = stat[:gid]

  @atime = stat[:atime]
  @ctime = stat[:ctime]
  @mtime = stat[:mtime]
end

Instance Attribute Details

#atimeTime? (readonly)

The access time of the file.

Returns:

  • (Time, nil)


86
87
88
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 86

def atime
  @atime
end

#blocksInteger (readonly)

The number of native file-system blocks

Returns:

  • (Integer)


51
52
53
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 51

def blocks
  @blocks
end

#blocksizeInteger (readonly) Also known as: blksize

The native file-system block size.

Returns:

  • (Integer)


56
57
58
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 56

def blocksize
  @blocksize
end

#ctimeTime (readonly)

The creation time of the file.

Returns:

  • (Time)


91
92
93
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 91

def ctime
  @ctime
end

#gidInteger (readonly)

The owner's GID of the file.

Returns:

  • (Integer)


81
82
83
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 81

def gid
  @gid
end

#inodeInteger (readonly) Also known as: ino

The Inode number

Returns:

  • (Integer)


61
62
63
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 61

def inode
  @inode
end

#modeInteger (readonly)

The mode of the file

Returns:

  • (Integer)


71
72
73
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 71

def mode
  @mode
end

#mtimeTime (readonly)

The modification time of the file.

Returns:

  • (Time)


96
97
98
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 96

def mtime
  @mtime
end

The number of hard links to the file

Returns:

  • (Integer)


66
67
68
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 66

def nlinks
  @nlinks
end

#pathString (readonly)

The path of the file

Returns:

  • (String)


41
42
43
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 41

def path
  @path
end

#sizeInteger (readonly)

The size of the file (in bytes)

Returns:

  • (Integer)


46
47
48
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 46

def size
  @size
end

#uidInteger (readonly)

The owner's UID of the file.

Returns:

  • (Integer)


76
77
78
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 76

def uid
  @uid
end

Instance Method Details

#zero?Boolean

Determines whether the file has zero size.

Returns:

  • (Boolean)

    Specifies whether the file has zero size.



167
168
169
# File 'lib/ronin/post_ex/remote_file/stat.rb', line 167

def zero?
  @size == 0
end