Module
FileUtils
In: lib/rake.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.rb, line 738
738:   def ruby(*args,&block)
739:     if Hash === args.last
740:       options = args.pop
741:     else
742:       options = {}
743:     end
744:     if args.length > 1 then
745:       sh(*([RUBY] + args + [options]), &block)
746:     else
747:       sh("#{RUBY} #{args}", options, &block)
748:     end
749:   end
safe_ln(*args)

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

     # File lib/rake.rb, line 755
755:   def safe_ln(*args)
756:     unless LN_SUPPORTED[0]
757:       cp(*args)
758:     else
759:       begin
760:         ln(*args)
761:       rescue StandardError, NotImplementedError
762:         LN_SUPPORTED[0] = false
763:         cp(*args)
764:       end
765:     end
766:   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.rb, line 712
712:   def sh(*cmd, &block)
713:     if Hash === cmd.last then
714:       options = cmd.pop
715:     else
716:       options = {}
717:     end
718:     unless block_given?
719:       show_command = cmd.join(" ")
720:       show_command = show_command[0,42] + "..." if show_command.length > 45
721:       block = lambda { |ok, status|
722:         ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
723:       }
724:     end
725:     fu_check_options options, :noop, :verbose
726:     fu_output_message cmd.join(" ") if options[:verbose]
727:     unless options[:noop]
728:       res = system(*cmd)      
729:       block.call(res, $?)
730:     end
731:   end
split_all(path)

Split a file path into individual directory names.

Example:

  split_all("a/b/c") =>  ['a', 'b', 'c']
     # File lib/rake.rb, line 773
773:   def split_all(path)
774:     head, tail = File.split(path)
775:     return [tail] if head == '.' || tail == '/'
776:     return [head, tail] if head == '/'
777:     return split_all(head) + [tail]
778:   end