-
-
Save headius/e20219b45fbe438d927f8655846a11c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- lib/ruby/stdlib/fileutils.rb 2022-04-20 14:27:30.000000000 -0500 | |
+++ ../ruby/lib/fileutils.rb 2022-03-26 16:46:17.000000000 -0500 | |
@@ -201,35 +201,28 @@ | |
# * /usr/local/lib | |
# * /usr/local/lib/ruby | |
# | |
# You can pass several directories at a time in a list. | |
# | |
def mkdir_p(list, mode: nil, noop: nil, verbose: nil) | |
list = fu_list(list) | |
fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose | |
return *list if noop | |
- list.map {|path| remove_trailing_slash(path)}.each do |path| | |
- # optimize for the most common case | |
- begin | |
- fu_mkdir path, mode | |
- next | |
- rescue SystemCallError | |
- next if File.directory?(path) | |
- end | |
+ list.each do |item| | |
+ path = remove_trailing_slash(item) | |
stack = [] | |
- until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/" | |
+ until File.directory?(path) | |
stack.push path | |
path = File.dirname(path) | |
end | |
- stack.pop # root directory should exist | |
stack.reverse_each do |dir| | |
begin | |
fu_mkdir dir, mode | |
rescue SystemCallError | |
raise unless File.directory?(dir) | |
end | |
end | |
end | |
return *list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment