Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify mkdir_p (and make it faster in some cases) #60

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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