PHP 8.2.31
Preview: alt_system.rb Size: 3.14 KB
//proc/thread-self/root/opt/alt/ruby20/lib64/ruby/2.0.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 and 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|
          if File.exist?(test = "#{file}.#{ext}")
            return test
          end
        }
        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: 42

Name Size Perms Modified Actions
contrib DIR
- drwxr-xr-x 2024-03-03 22:53:08
Edit Download
ext DIR
- drwxr-xr-x 2024-03-03 22:53:08
Edit Download
lib DIR
- drwxr-xr-x 2024-03-03 22:53:08
Edit Download
loaders DIR
- drwxr-xr-x 2024-03-03 22:53:08
Edit Download
3.14 KB lrw-r--r-- 2011-06-23 22:11:55
Edit Download
21.27 KB lrw-r--r-- 2012-11-29 19:16:46
Edit Download
622 B lrw-r--r-- 2012-11-30 03:21:06
Edit Download
408 B lrw-r--r-- 2011-06-28 02:45:29
Edit Download
1.00 KB lrw-r--r-- 2012-11-15 21:59:37
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
5.02 KB lrw-r--r-- 2012-11-15 21:59:37
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.50 KB lrw-r--r-- 2012-11-29 19:16:46
Edit Download
1.28 KB lrw-r--r-- 2011-06-23 22:11:55
Edit Download
3.01 KB lrw-r--r-- 2012-12-06 07:35:45
Edit Download
4.10 KB lrw-r--r-- 2012-11-15 21:59:37
Edit Download
283 B lrw-r--r-- 2011-06-28 02:45:29
Edit Download
962 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
431 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
315 B lrw-r--r-- 2012-11-15 21:59:37
Edit Download
618 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
5.07 KB lrw-r--r-- 2011-06-23 22:11:55
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.33 KB lrw-r--r-- 2012-11-15 22:01:58
Edit Download
422 B lrw-r--r-- 2011-06-23 22:11:55
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
6.55 KB lrw-r--r-- 2012-11-15 21:59:37
Edit Download
843 B lrw-r--r-- 2012-11-22 05:32:31
Edit Download
353 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
468 B lrw-r--r-- 2012-11-15 22:32:34
Edit Download
10.17 KB lrw-r--r-- 2012-11-29 19:16:46
Edit Download
580 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
1.63 KB lrw-r--r-- 2012-11-15 21:59:37
Edit Download
119 B lrw-r--r-- 2011-06-23 22:11:55
Edit Download
8.78 KB lrw-r--r-- 2012-11-15 21:59:37
Edit Download
5.18 KB lrw-r--r-- 2012-11-15 22:32:34
Edit Download
1.10 KB lrw-r--r-- 2012-11-15 22:01:58
Edit Download
4.67 KB lrw-r--r-- 2012-11-15 22:01:58
Edit Download
488 B lrw-r--r-- 2012-11-29 19:16:46
Edit Download
187 B lrw-r--r-- 2012-12-21 02:34:37
Edit Download
1.53 KB lrw-r--r-- 2011-06-23 22:11:55
Edit Download

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