Module: Metasploit::Model::File

Defined in:
lib/metasploit/model/file.rb

Overview

Re-implement methods on ruby's File that are buggy in JRuby so that the platform specific logic can be in this module instead of everywhere these methods are used.

Class Method Summary collapse

Class Method Details

.method_missing(method_name, *args, &block) ⇒ Object

Delegates to ::File if ::File supports the method when Metasploit::Model::File does not implement an override to fix different platform incompatibilities.

Parameters:

  • method_name (Symbol)

    name of method.

  • args (Array)

    arguments passed to method with name method_name.

  • block (Proc)

    block to pass after args to method with name method_name.



30
31
32
33
34
35
36
# File 'lib/metasploit/model/file.rb', line 30

def method_missing(method_name, *args, &block)
  if ::File.respond_to?(method_name)
    ::File.public_send(method_name, *args, &block)
  else
    super
  end
end

.realpath(path) ⇒ String

On JRuby, File.realpath does not resolve symlinks, so need to drop to Java to get the real path.

Parameters:

  • path (String)

    a path that may contain '.', '..', or symlinks

Returns:

  • (String)

    canonical path

See Also:



16
17
18
19
20
# File 'lib/metasploit/model/file.rb', line 16

def self.realpath(path)
  file = java.io.File.new(path)

  file.canonical_path
end

.respond_to?(method_name, include_private = false) ⇒ Boolean

Whether this module or ::File responds to method_name.

Parameters:

  • method_name (Symbol)

    name of method.

  • include_private (Boolean) (defaults to: false)

    whether to include private methods.

Returns:

  • (Boolean)


43
44
45
# File 'lib/metasploit/model/file.rb', line 43

def respond_to?(method_name, include_private=false)
  ::File.respond_to?(method_name, include_private) || super
end