Module
FileUtils
In: lib/rake/file_utils.rb

########################################################################### This a FileUtils extension that defines several additional commands to be added to the FileUtils utility functions.

Methods

ruby, safe_ln, sh, split_all,
Public Instance methods
ruby(*args,&block)

Run a Ruby interpreter with the given arguments.

Example:

  ruby %{-pe '$_.upcase!' <README}
    # File lib/rake/file_utils.rb, line 75
75:   def ruby(*args,&block)
76:     options = (Hash === args.last) ? args.pop : {}
77:     if args.length > 1 then
78:       sh(*([RUBY] + args + [options]), &block)
79:     else
80:       sh("#{RUBY} #{args.first}", options, &block)
81:     end
82:   end
safe_ln(*args)

Attempt to do a normal file link, but fall back to a copy if the link fails.

    # File lib/rake/file_utils.rb, line 88
88:   def safe_ln(*args)
89:     unless LN_SUPPORTED[0]
90:       cp(*args)
91:     else
92:       begin
93:         ln(*args)
94:       rescue StandardError, NotImplementedError => ex
95:         LN_SUPPORTED[0] = false
96:         cp(*args)
97:       end
98:     end
99:   end
sh(*cmd, &block)

Run the system command cmd. If multiple arguments are given the command is not run with the shell (same semantics as Kernel::exec and Kernel::system).

Example:

  sh %{ls -ltr}

  sh 'ls', 'file with spaces'

  # check exit status after command runs
  sh %{grep pattern file} do |ok, res|
    if ! ok
      puts "pattern not found (status = #{res.exitstatus})"
    end
  end
    # File lib/rake/file_utils.rb, line 34
34:   def sh(*cmd, &block)
35:     options = (Hash === cmd.last) ? cmd.pop : {}
36:     shell_runner = block_given? ? block : create_shell_runner(cmd)
37:     set_verbose_option(options)
38:     options[:noop] ||= Rake::FileUtilsExt.nowrite_flag
39:     Rake.rake_check_options options, :noop, :verbose
40:     Rake.rake_output_message cmd.join(" ") if options[:verbose]
41:     unless options[:noop]
42:       res = rake_system(*cmd)
43:       status = $?
44:       status = PseudoStatus.new(1) if !res && status.nil?
45:       shell_runner.call(res, status)
46:     end
47:   end
split_all(path)

Split a file path into individual directory names.

Example:

  split_all("a/b/c") =>  ['a', 'b', 'c']
     # File lib/rake/file_utils.rb, line 106
106:   def split_all(path)
107:     head, tail = File.split(path)
108:     return [tail] if head == '.' || tail == '/'
109:     return [head, tail] if head == '/'
110:     return split_all(head) + [tail]
111:   end