Skip to content

Commit

Permalink
Merge pull request #60 from deivid-rodriguez/speed_up_mkdir_p
Browse files Browse the repository at this point in the history
Simplify `mkdir_p` (and make it faster in some cases)
  • Loading branch information
hsbt authored Oct 14, 2021
2 parents 0bb0e2f + e842a0e commit 8a6de48
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,11 @@ def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
list.each do |item|
path = remove_trailing_slash(item)

# optimize for the most common case
begin
fu_mkdir path, mode
next
rescue SystemCallError
next if File.directory?(path)
end

stack = []
until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
until File.directory?(path)
stack.push path
path = File.dirname(path)
break if File.directory?(path)
end
stack.pop if path == stack.last # root directory should exist
stack.reverse_each do |dir|
begin
fu_mkdir dir, mode
Expand Down

0 comments on commit 8a6de48

Please sign in to comment.