summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-04 15:44:53 +0000
committerktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-04 15:44:53 +0000
commitdf0991f34b95e4f6a283c40613aac0334accce1e (patch)
tree6e7a18283edca3fdde2a8f0791671065316f1b3a
parent77cf13a588be5bab7efa44eccf097ca579a41ae4 (diff)
* ext/pathname/lib/pathname.rb (Pathname#find): add "ignore_error"
keyword argument defaulted to true as well as Find#find. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/pathname/lib/pathname.rb8
-rw-r--r--test/pathname/test_pathname.rb25
3 files changed, 34 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 82c9846021..3fa801b179 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Mar 5 00:42:00 2014 Kazuki Tsujimoto <kazuki@callcc.net>
+
+ * ext/pathname/lib/pathname.rb (Pathname#find): add "ignore_error"
+ keyword argument defaulted to true as well as Find#find.
+
Tue Mar 4 23:00:18 2014 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_eval.rb (TestEval#make_test_binding): renamed.
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
index 46fa72b784..20c92e23dc 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -534,13 +534,13 @@ class Pathname # * Find *
#
# See Find.find
#
- def find # :yield: pathname
- return to_enum(__method__) unless block_given?
+ def find(ignore_error: true) # :yield: pathname
+ return to_enum(__method__, ignore_error: ignore_error) unless block_given?
require 'find'
if @path == '.'
- Find.find(@path) {|f| yield self.class.new(f.sub(%r{\A\./}, '')) }
+ Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f.sub(%r{\A\./}, '')) }
else
- Find.find(@path) {|f| yield self.class.new(f) }
+ Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f) }
end
end
end
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 8008e8c0af..ed79b5b8f5 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1253,6 +1253,31 @@ class TestPathname < Test::Unit::TestCase
assert_equal([Pathname("."), Pathname("a"), Pathname("b"), Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
a = Pathname("d").find.sort
assert_equal([Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
+
+ begin
+ File.unlink("d/y")
+ File.chmod(0600, "d")
+ a = []; Pathname(".").find(ignore_error: true) {|v| a << v }; a.sort!
+ assert_equal([Pathname("."), Pathname("a"), Pathname("b"), Pathname("d"), Pathname("d/x")], a)
+ a = []; Pathname("d").find(ignore_error: true) {|v| a << v }; a.sort!
+ assert_equal([Pathname("d"), Pathname("d/x")], a)
+
+ skip "no meaning test on Windows" if /mswin|mingw/ =~ RUBY_PLATFORM
+ a = [];
+ assert_raise_with_message(Errno::EACCES, %r{d/x}) do
+ Pathname(".").find(ignore_error: false) {|v| a << v }
+ end
+ a.sort!
+ assert_equal([Pathname("."), Pathname("a"), Pathname("b"), Pathname("d"), Pathname("d/x")], a)
+ a = [];
+ assert_raise_with_message(Errno::EACCES, %r{d/x}) do
+ Pathname("d").find(ignore_error: false) {|v| a << v }
+ end
+ a.sort!
+ assert_equal([Pathname("d"), Pathname("d/x")], a)
+ ensure
+ File.chmod(0700, "d")
+ end
}
end