/usr/lib/ruby/vendor_ruby/mini_magick/utilities.rb is in ruby-mini-magick 3.8.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | require 'rbconfig'
require 'shellwords'
require 'pathname'
module MiniMagick
module Utilities
class << self
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable? exe
end
end
nil
end
# Finds out if the host OS is windows
def windows?
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
def escape(value)
if windows?
windows_escape(value)
else
shell_escape(value)
end
end
def shell_escape(value)
Shellwords.escape(value)
end
def windows_escape(value)
# For Windows, ^ is the escape char, equivalent to \ in Unix.
escaped = value.gsub(/\^/, '^^').gsub(/>/, '^>')
if escaped !~ /^".+"$/ && escaped.include?("'")
escaped.inspect
else
escaped
end
end
def path(path)
if windows?
# For Windows, if a path contains space char, you need to quote it,
# otherwise you SHOULD NOT quote it. If you quote a path that does
# not contains space, it will not work.
pathname = Pathname.new(path).to_s
path.include?(' ') ? pathname.inspect : pathname
else
path
end
end
end
end
end
|