PHP 8.2.31
Preview: alt_system.rb Size: 3.13 KB
//proc/thread-self/root/opt/alt/ruby21/lib64/ruby/2.1.0/rake/alt_system.rb

#
# Copyright (c) 2008 James M. Lawrence
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

require 'rbconfig'

#
# Alternate implementations of system() and backticks `` on Windows
# for ruby-1.8 and earlier.
#
module Rake::AltSystem
  WINDOWS = RbConfig::CONFIG["host_os"] =~
    %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!

  class << self
    def define_module_function(name, &block)
      define_method(name, &block)
      module_function(name)
    end
  end

  if WINDOWS && RUBY_VERSION < "1.9.0"
    RUNNABLE_EXTS = %w[com exe bat cmd]
    RUNNABLE_PATTERN = %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i

    define_module_function :kernel_system, &Kernel.method(:system)
    define_module_function :kernel_backticks, &Kernel.method(:'`')

    module_function

    def repair_command(cmd)
      "call " + (
        if cmd =~ %r!\A\s*\".*?\"!
          # already quoted
          cmd
        elsif match = cmd.match(%r!\A\s*(\S+)!)
          if match[1] =~ %r!/!
            # avoid x/y.bat interpretation as x with option /y
            %Q!"#{match[1]}"! + match.post_match
          else
            # a shell command will fail if quoted
            cmd
          end
        else
          # empty or whitespace
          cmd
        end
      )
    end

    def find_runnable(file)
      if file =~ RUNNABLE_PATTERN
        file
      else
        RUNNABLE_EXTS.each { |ext|
          test = "#{file}.#{ext}"
          return test if File.exist?(test)
        }
        nil
      end
    end

    def system(cmd, *args)
      repaired = (
        if args.empty?
          [repair_command(cmd)]
        elsif runnable = find_runnable(cmd)
          [File.expand_path(runnable), *args]
        else
          # non-existent file
          [cmd, *args]
        end
      )
      kernel_system(*repaired)
    end

    def backticks(cmd)
      kernel_backticks(repair_command(cmd))
    end

    define_module_function :'`', &method(:backticks)
  else
    # Non-Windows or ruby-1.9+: same as Kernel versions
    define_module_function :system, &Kernel.method(:system)
    define_module_function :backticks, &Kernel.method(:'`')
    define_module_function :'`', &Kernel.method(:'`')
  end
end

Directory Contents

Dirs: 4 × Files: 43

Name Size Perms Modified Actions
contrib DIR
- drwxr-xr-x 2024-03-03 22:53:20
Edit Download
ext DIR
- drwxr-xr-x 2024-03-03 22:53:20
Edit Download
lib DIR
- drwxr-xr-x 2024-03-03 22:53:20
Edit Download
loaders DIR
- drwxr-xr-x 2024-03-03 22:53:20
Edit Download
3.13 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
20.78 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
715 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.37 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
482 B lrw-r--r-- 2012-11-15 21:59:37
Edit Download
164 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
4.15 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
273 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
670 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
11.82 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.28 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
3.03 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
4.05 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
116 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.23 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
431 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
2.27 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
315 B lrw-r--r-- 2012-11-15 21:59:37
Edit Download
618 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
5.11 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
26 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
351 B lrw-r--r-- 2012-11-15 22:32:34
Edit Download
364 B lrw-r--r-- 2012-11-15 22:01:58
Edit Download
2.28 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
427 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
727 B lrw-r--r-- 2012-11-15 22:32:34
Edit Download
341 B lrw-r--r-- 2011-06-28 02:45:29
Edit Download
126 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
870 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
353 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
471 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
868 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
10.96 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
580 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.88 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
119 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
8.40 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
5.22 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.11 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
4.74 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download
529 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
178 B lrw-r--r-- 2013-10-11 21:35:01
Edit Download
1.54 KB lrw-r--r-- 2013-10-11 21:35:01
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).