Skip to content

Commit 867ae62

Browse files
nobuhsbt
authored andcommitted
[Feature #16972] Add mode: option to Pathname#mkpath
1 parent 1a02058 commit 867ae62

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/pathname.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ class Pathname # * FileUtils *
581581
# exist.
582582
#
583583
# See FileUtils.mkpath and FileUtils.mkdir_p
584-
def mkpath
585-
FileUtils.mkpath(@path)
584+
def mkpath(mode: nil)
585+
FileUtils.mkpath(@path, mode: mode)
586586
nil
587587
end
588588

test/pathname/test_pathname.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,22 @@ def test_find
14291429
}
14301430
end
14311431

1432+
def assert_mode(val, mask, path, mesg = nil)
1433+
st = File.stat(path)
1434+
assert_equal(val.to_s(8), (st.mode & mask).to_s(8), st.inspect)
1435+
end
1436+
14321437
def test_mkpath
14331438
with_tmpchdir('rubytest-pathname') {|dir|
14341439
Pathname("a/b/c/d").mkpath
14351440
assert_file.directory?("a/b/c/d")
1441+
unless File.stat(dir).world_readable?
1442+
# mktmpdir should make unreadable
1443+
Pathname("x/y/z").mkpath(mode: 0775)
1444+
assert_mode(0775, 0777, "x")
1445+
assert_mode(0775, 0777, "x/y")
1446+
assert_mode(0775, 0777, "x/y/z")
1447+
end
14361448
}
14371449
end
14381450

0 commit comments

Comments
 (0)