Sha256: cf5cd497bf3d4ca8357cb0c25b7d37dec5809bb59d4bcf9fa983eaa652f845ec

Contents?: true

Size: 1.71 KB

Versions: 30

Compression:

Stored size: 1.71 KB

Contents

if RUBY_PLATFORM =~ /java/ && Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('1.7.14')
  require 'java'

  # 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.
  module Metasploit::Model::File
    # On JRuby (< 1.7.14), File.realpath does not resolve symlinks, so need to drop to Java to get the real path.
    #
    # @param path [String] a path that may contain `'.'`, `'..'`, or symlinks
    # @return [String] canonical path
    # @see https://github.com/jruby/jruby/issues/538
    def self.realpath(path)
      file = java.io.File.new(path)

      file.canonical_path
    end

    class << self
      # Delegates to `::File` if `::File` supports the method when {Metasploit::Model::File} does not implement an
      # override to fix different platform incompatibilities.
      #
      # @param method_name [Symbol] name of method.
      # @param args [Array] arguments passed to method with name `method_name`.
      # @param block [Proc] block to pass after `args` to method with name `method_name`.
      def method_missing(method_name, *args, &block)
        if ::File.respond_to?(method_name)
          ::File.public_send(method_name, *args, &block)
        else
          super
        end
      end

      # Whether this module or `::File` responds to `method_name`.
      #
      # @param method_name [Symbol] name of method.
      # @param include_private [Boolean] whether to include private methods.
      # @return [Boolean]
      def respond_to?(method_name, include_private=false)
        ::File.respond_to?(method_name, include_private) || super
      end
    end
  end
else
  Metasploit::Model::File = ::File
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
metasploit-model-3.1.2 lib/metasploit/model/file.rb
metasploit-model-3.1.1 lib/metasploit/model/file.rb
metasploit-model-3.1.0 lib/metasploit/model/file.rb
metasploit-model-3.0.0 lib/metasploit/model/file.rb
metasploit-model-2.0.4 lib/metasploit/model/file.rb
metasploit-model-2.0.3 lib/metasploit/model/file.rb
metasploit-model-2.0.2 lib/metasploit/model/file.rb
metasploit-model-2.0.1 lib/metasploit/model/file.rb
metasploit-model-2.0.0 lib/metasploit/model/file.rb
metasploit-model-1.1.0 lib/metasploit/model/file.rb
metasploit-model-1.0.2 lib/metasploit/model/file.rb
metasploit-model-1.0.1 lib/metasploit/model/file.rb
metasploit-model-1.0.0 lib/metasploit/model/file.rb
metasploit-model-0.30.2 lib/metasploit/model/file.rb
metasploit-model-0.30.2-java lib/metasploit/model/file.rb
metasploit-model-0.30.1 lib/metasploit/model/file.rb
metasploit-model-0.30.1-java lib/metasploit/model/file.rb
metasploit-model-0.30.1.pre.rspec.pre.3.pre.1 lib/metasploit/model/file.rb
metasploit-model-1.0.0.pre.rails.pre.4.0 lib/metasploit/model/file.rb
metasploit-model-0.30.0 lib/metasploit/model/file.rb