[前][次][番号順一覧][スレッド一覧]

ruby-changes:67380

From: Nobuyoshi <ko1@a...>
Date: Tue, 31 Aug 2021 11:54:06 +0900 (JST)
Subject: [ruby-changes:67380] 2dd26bed86 (master): [Feature #16972] Add mode: option to Pathname#mkpath

https://git.ruby-lang.org/ruby.git/commit/?id=2dd26bed86

From 2dd26bed86f721ed1982d00c3a0bd5ed37568e96 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 21 Jun 2020 11:33:09 +0900
Subject: [Feature #16972] Add mode: option to Pathname#mkpath

---
 ext/pathname/lib/pathname.rb   |  4 ++--
 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 c3af248..3799d58 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -581,8 +581,8 @@ class Pathname    # * FileUtils * https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L581
   # 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 8a0f3cb..a83eb1f 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1429,10 +1429,22 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L1429
     }
   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
 
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]