diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-06-21 11:33:09 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-31 11:53:41 +0900 |
commit | 2dd26bed86f721ed1982d00c3a0bd5ed37568e96 (patch) | |
tree | 643dc7e2689fba87ce97536d0d0f85606c3f82ea | |
parent | 181207e830cc8fb0fac78e9bcd4163c25831c600 (diff) | |
download | ruby-2dd26bed86f721ed1982d00c3a0bd5ed37568e96.tar.gz |
[Feature #16972] Add mode: option to Pathname#mkpath
-rw-r--r-- | ext/pathname/lib/pathname.rb | 4 | ||||
-rw-r--r-- | test/pathname/test_pathname.rb | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index c3af24837f..3799d589d5 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -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 diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 8a0f3cbb66..a83eb1ffcf 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -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 |