1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Feature ] Add mode: option to Pathname#mkpath

This commit is contained in:
Nobuyoshi Nakada 2020-06-21 11:33:09 +09:00 committed by Hiroshi SHIBATA
parent 181207e830
commit 2dd26bed86
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 14 additions and 2 deletions
ext/pathname/lib
test/pathname

View file

@ -581,8 +581,8 @@ class Pathname # * FileUtils *
# exist.
#
# See FileUtils.mkpath and FileUtils.mkdir_p
def mkpath
FileUtils.mkpath(@path)
def mkpath(mode: nil)
FileUtils.mkpath(@path, mode: mode)
nil
end

View file

@ -1429,10 +1429,22 @@ class TestPathname < Test::Unit::TestCase
}
end
def assert_mode(val, mask, path, mesg = nil)
st = File.stat(path)
assert_equal(val.to_s(8), (st.mode & mask).to_s(8), st.inspect)
end
def test_mkpath
with_tmpchdir('rubytest-pathname') {|dir|
Pathname("a/b/c/d").mkpath
assert_file.directory?("a/b/c/d")
unless File.stat(dir).world_readable?
# mktmpdir should make unreadable
Pathname("x/y/z").mkpath(mode: 0775)
assert_mode(0775, 0777, "x")
assert_mode(0775, 0777, "x/y")
assert_mode(0775, 0777, "x/y/z")
end
}
end