Home > Mobile >  If you connect the mkmf library to the rails, then some uploaded files break
If you connect the mkmf library to the rails, then some uploaded files break

Time:08-20

require 'mkmf'
class BashTest
  def example_ruby_path
    find_executable 'ruby'
  end
end

If so, connect the library 'mkmf'. Then rails can sometimes raise such an exception:

ActionView::Template::Error: not opened for reading

Or other random exceptions. Basically, this happened on ruby 2.7 and 6 rails. This happens less often on 3.1.2 and 7 rails.

lib: https://github.com/ruby/ruby/blob/master/lib/mkmf.rb

docs: https://ruby-doc.org/stdlib-2.5.1/libdoc/mkmf/rdoc/MakeMakefile.html

In principle, I understand that, in theory, this connection changes the connections of c files, but is the standard connection of c files so different, and why does this happen globally in the entire project when I connect this library in only one file?

CodePudding user response:

This happens because this library overwrites some global variables. If you need to search for a file, a binary file, you can try to implement it using code (only linux based os):

class FindBinary
  class << self
    def path(binary)
      ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
        binary_path = File.join(path, binary)
        return binary_path if File.executable?(binary_path) && !File.directory?(binary_path)
      end
      nil
    end
  end
end

Or other workarounds.

  • Related