mkdir_p(list, options = {})
private
Options: mode noop verbose
Creates a directory and all its parent directories. For example,
FileUtils.mkdir_p '/usr/local/lib/ruby'
causes to make following directories, if it does not exist.
* /usr
* /usr/local
* /usr/local/lib
* /usr/local/lib/ruby
You can pass several directories at a time in a list.
Show source
def mkdir_p(list, options = {})
fu_check_options options, OPT_TABLE['mkdir_p']
list = fu_list(list)
fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
return *list if options[:noop]
list.map {|path| path.sub(%</\z>, '') }.each do |path|
begin
fu_mkdir path, options[:mode]
next
rescue SystemCallError
next if File.directory?(path)
end
stack = []
until path == stack.last
stack.push path
path = File.dirname(path)
end
stack.reverse_each do |dir|
begin
fu_mkdir dir, options[:mode]
rescue SystemCallError
raise unless File.directory?(dir)
end
end
end
return *list
end