Skip to content

Commit 8a6de48

Browse files
authored
Merge pull request #60 from deivid-rodriguez/speed_up_mkdir_p
Simplify `mkdir_p` (and make it faster in some cases)
2 parents 0bb0e2f + e842a0e commit 8a6de48

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

lib/fileutils.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,11 @@ def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
211211
list.each do |item|
212212
path = remove_trailing_slash(item)
213213

214-
# optimize for the most common case
215-
begin
216-
fu_mkdir path, mode
217-
next
218-
rescue SystemCallError
219-
next if File.directory?(path)
220-
end
221-
222214
stack = []
223-
until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
215+
until File.directory?(path)
224216
stack.push path
225217
path = File.dirname(path)
226-
break if File.directory?(path)
227218
end
228-
stack.pop if path == stack.last # root directory should exist
229219
stack.reverse_each do |dir|
230220
begin
231221
fu_mkdir dir, mode

0 commit comments

Comments
 (0)