class File
Work around for a bug in File.expand_path
that doesn't account for resources in jar paths.
Should solve this error:
Exception in thread "LogStash::Runner" org.jruby.exceptions.RaiseException: (Errno::ENOENT) file:/home/jls/projects/logstash/build/data/unicode.data
Constants
- JAR_RE
Public Class Methods
__zipcache(jarpath, path)
click to toggle source
# File lib/logstash/monkeypatches-for-performance.rb, line 46 def __zipcache(jarpath, path) @jarcache ||= Hash.new { |h,k| h[k] = {} } if @jarcache[jarpath].empty? #puts "Caching file entries for #{jarpath}" s = Time.now zip = java.util.zip.ZipFile.new(jarpath) zip.entries.each do |entry| #puts "Caching file entries for #{jarpath}: /#{entry.name}" # Prefix entry name with "/" because that's what the jar path looks # like in jruby: file://some.jar!/some/path @jarcache[jarpath]["/" + entry.name] = entry end end entry = @jarcache[jarpath][path] #puts "Serving cached file info #{path}: #{entry}" return entry end
exist?(path)
click to toggle source
# File lib/logstash/monkeypatches-for-performance.rb, line 28 def exist?(path) #return mpp_exist?(path) # If path is in a jar (file://blah/foo.jar!/some/path) # - create a cache for this jar of all files # - return cached results only if RUBY_PLATFORM == "java" m = JAR_RE.match(path) return mpp_exists?(path) if !m # not a jar file c = __zipcache(m[1], m[2]) # m[1] == the jar path return !c.nil? end return mpp_exists?(path) end
Also aliased as: mpp_exist?
exists?(path)
click to toggle source
# File lib/logstash/monkeypatches-for-performance.rb, line 42 def exists?(path) return exist?(path) end
Also aliased as: mpp_exists?
expand_path(path, dir=nil)
click to toggle source
# File lib/logstash/JRUBY-6970.rb, line 47 def expand_path(path, dir=nil) #p :expand_path => [path, dir] if path =~ /(jar:)?file:\/.*\.jar!/ #p :expand_path_path => [path, dir] jar, resource = path.split("!", 2) #p :expand_path => [jar, resource] if resource.nil? || resource == "" # Nothing after the "!", nothing special to handle. return expand_path_JRUBY_6970(path, dir) else resource = expand_path_JRUBY_6970(resource, dir) return fix_jar_path(jar, resource) end elsif dir =~ /(jar:)?file:\/.*\.jar!/ jar, dir = dir.split("!", 2) if dir.empty? # sometimes the original dir is just 'file:/foo.jar!' return File.join("#{jar}!", path) end dir = expand_path_JRUBY_6970(path, dir) return fix_jar_path(jar, dir) else return expand_path_JRUBY_6970(path, dir) end end
Also aliased as: expand_path_JRUBY_6970
file?(path)
click to toggle source
# File lib/logstash/monkeypatches-for-performance.rb, line 10 def file?(path) #return mpp_file?(path) # If path is in a jar (file://blah/foo.jar!/some/path) # - create a cache for this jar of all files # - return cached results only if RUBY_PLATFORM == "java" m = JAR_RE.match(path) return mpp_file?(path) if !m # not a jar file c = __zipcache(m[1], m[2]) # m[1] == the jar path # ZipEntry has only 'isDirectory()' so I assume any # non-directories are files. rc = (!c.nil? && !c.isDirectory) #p path => rc return rc end return mpp_file?(path) end
Also aliased as: mpp_file?
Protected Class Methods
fix_jar_path(jar, resource)
click to toggle source
# File lib/logstash/JRUBY-6970.rb, line 76 def self.fix_jar_path(jar, resource) # TODO(sissel): use LogStash::Util::UNAME if RbConfig::CONFIG["host_os"] == "mswin32" # 'expand_path' on "/" will return "C:/" on windows. # So like.. we don't want that because technically this # is the root of the jar, not of a disk. #puts :fix_jar_path => ["#{jar}!#{resource.gsub(/^[A-Za-z]:/, "")}"] return "#{jar}!#{resource.gsub(/^[A-Za-z]:/, "")}" else return "#{jar}!#{resource}" end end