[#85940] [Ruby trunk Bug#14578] Forking a child process inside of a mutex crashes the ruby interpreter — ben.govero@...
Issue #14578 has been reported by bengovero (Ben Govero).
3 messages
2018/03/05
[#86205] [Ruby trunk Feature#14618] Add display width method to String for CLI — aycabta@...
SXNzdWUgIzE0NjE4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGF5Y2FidGEgKGF5Y2FidGEgLikuCgot
3 messages
2018/03/19
[#86366] Re: [ruby-cvs:70102] usa:r63008 (trunk): get rid of test error/failure on Windows introduced at r62955 — Eric Wong <normalperson@...>
[email protected] wrote:
3 messages
2018/03/28
[ruby-core:85871] [Ruby trunk Feature#12010] Exclude dot and dotdot from Dir#each
From:
nobu@...
Date:
2018-03-01 01:13:36 UTC
List:
ruby-core #85871
Issue #12010 has been updated by nobu (Nobuyoshi Nakada).
This can be closed by #13969?
----------------------------------------
Feature #12010: Exclude dot and dotdot from Dir#each
https://bugs.ruby-lang.org/issues/12010#change-70728
* Author: naruse (Yui NARUSE)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
`Dir#each` and `Dir#read` (including `Dir.entries`, `Dir.foreach` and other methods) return `"."` and `".."` at first.
But through the all real use case `"."` and `".."` are useless.
How about excluding them?
```diff
diff --git a/dir.c b/dir.c
index 193b5be..4c23a2d 100644
--- a/dir.c
+++ b/dir.c
@@ -699,6 +699,8 @@ fundamental_encoding_p(rb_encoding *enc)
#else
# define READDIR(dir, enc) readdir((dir))
#endif
+#define DIR_IS_DOT_OR_DOTDOT(dp) ((dp)->d_name[0] == '.' && \
+ ((dp)->d_name[1] == '\0' || ((dp)->d_name[1] == '.' && (dp)->d_name[2] == '\0')))
/*
* call-seq:
@@ -720,13 +722,12 @@ dir_read(VALUE dir)
GetDIR(dir, dirp);
errno = 0;
- if ((dp = READDIR(dirp->dir, dirp->enc)) != NULL) {
- return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
- }
- else {
- if (errno != 0) rb_sys_fail(0);
- return Qnil; /* end of stream */
+ while ((dp = READDIR(dirp->dir, dirp->enc)) != NULL) {
+ if (!DIR_IS_DOT_OR_DOTDOT(dp))
+ return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
}
+ if (errno != 0) rb_sys_fail(0);
+ return Qnil; /* end of stream */
}
/*
@@ -764,6 +765,7 @@ dir_each(VALUE dir)
const char *name = dp->d_name;
size_t namlen = NAMLEN(dp);
VALUE path;
+ if (DIR_IS_DOT_OR_DOTDOT(dp)) continue;
#if NORMALIZE_UTF8PATH
if (norm_p && has_nonascii(name, namlen) &&
!NIL_P(path = rb_str_normalize_ospath(name, namlen))) {
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 2690a3f..33f0d44 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1238,7 +1238,7 @@ def test_entries
with_tmpchdir('rubytest-pathname') {|dir|
open("a", "w") {}
open("b", "w") {}
- assert_equal([Pathname("."), Pathname(".."), Pathname("a"), Pathname("b")], Pathname(".").entries.sort)
+ assert_equal([Pathname("a"), Pathname("b")], Pathname(".").entries.sort)
}
end
@@ -1248,7 +1248,7 @@ def test_each_entry
open("b", "w") {}
a = []
Pathname(".").each_entry {|v| a << v }
- assert_equal([Pathname("."), Pathname(".."), Pathname("a"), Pathname("b")], a.sort)
+ assert_equal([Pathname("a"), Pathname("b")], a.sort)
}
end
@@ -1278,7 +1278,7 @@ def test_opendir
Pathname(".").opendir {|d|
d.each {|e| a << e }
}
- assert_equal([".", "..", "a", "b"], a.sort)
+ assert_equal(["a", "b"], a.sort)
}
end
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 0cc5a6a..d3f6602 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -186,7 +186,7 @@ def test_glob_recursive
def assert_entries(entries)
entries.sort!
- assert_equal(%w(. ..) + ("a".."z").to_a, entries)
+ assert_equal(("a".."z").to_a, entries)
end
def test_entries
```
---Files--------------------------------
dir-entries-usages.txt (304 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>