mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Feature #16972] Add mode: option to Pathname#mkpath
This commit is contained in:
parent
181207e830
commit
2dd26bed86
2 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue