[#72745] [Ruby trunk - Misc #11876] [Closed] Scheduled maintenance 2016/01/01 — shibata.hiroshi@...
Issue #11876 has been updated by Hiroshi SHIBATA.
shibata.hiroshi@gmail.com wrote:
[#72824] [Ruby trunk - Bug #11973] IO#advise should raise NotImplementedError on platforms that do not support that call — git@...
Issue #11973 has been updated by Chuck Remes.
[#72954] [Ruby trunk - Feature #12010] [Assigned] Exclude dot and dotdot from Dir#each — naruse@...
Issue #12010 has been reported by Yui NARUSE.
naruse@airemix.jp wrote:
[#73313] [Ruby trunk - Bug #12007] [Open] Newly added Unicode data file doesn't get downloaded — shugo@...
SXNzdWUgIzEyMDA3IGhhcyBiZWVuIHVwZGF0ZWQgYnkgU2h1Z28gTWFlZGEuCgpTdGF0dXMgY2hh
[#73372] [Ruby trunk - Misc #12004] Code of Conduct — benton@...
Issue #12004 has been updated by Benton Barnett.
On Sun, Jan 24, 2016 at 5:13 PM, <benton@bentonbarnett.com> wrote:
[#73421] [Ruby trunk - Misc #12004] Code of Conduct — nekocat432@...
Issue #12004 has been updated by Ruby Dino.
I=E2=80=99m sorry, but this, like the code of merit, is merely a derailing =
T24gMjAxNi8wMS8yNiAwMTozMiwgQXVzdGluIFppZWdsZXIgd3JvdGU6Cj4gSeKAmW0gc29ycnks
On Tue, Jan 26, 2016 at 12:25 AM, Martin J. D=C3=BCrst <duerst@it.aoyama.ac=
[#73491] [Ruby trunk - Misc #12004] Code of Conduct — git@...
Issue #12004 has been updated by Chuck Remes.
They will never provide any numbers because they are not engineers and they
Coraline is a panelist on Ruby rogues and a very well respected member of
OK, sorry for previous comment. Let's try this way.
On Tue, Jan 26, 2016 at 5:15 PM, Andrew Kirilenko <
[#73558] [Ruby trunk - Misc #12004] Code of Conduct — andrew.kirilenko@...
Issue #12004 has been updated by Andrew Kirilenko.
Andrew, please stop digging. Your hole is only getting deeper.
>Andrew, please stop digging. Your hole is only getting deeper.
[#73586] [Ruby trunk - Misc #12004] Code of Conduct — andrew@...
Issue #12004 has been updated by Andrew Vit.
[#73593] [Ruby trunk - Bug #12034] RegExp does not respect file encoding directive — nobu@...
Issue #12034 has been updated by Nobuyoshi Nakada.
[ruby-core:73308] [Ruby trunk - Feature #12010] Exclude dot and dotdot from Dir#each
Issue #12010 has been updated by Robert A. Heiler.
> default it to include to make migration easier
I dunno. I never found a usecase for '.' and '..' so I would have no migration need at
all since I did not use it. And in the old cases where I used it, I always ended
up filtering away the '.' and '..' since I have no idea what to do with it.
But I also do not use Dir.entries much at all either since many years. I fell in love
with Dir[] and have been using that ever since, respectively Dir['*'] or any other
filter. I assume that perhaps Dir.entries() is not used that much in "modern" ruby
code.
I did a grep in the rack-1.6.4 source, just to use something as reference :-)
4 Instances of Dir[], one in lib/rack/directory.rb, two in rack.gemspec,
one in a Rakefile.
And no instance of Dir.entries hehe
----------------------------------------
Feature #12010: Exclude dot and dotdot from Dir#each
https://bugs.ruby-lang.org/issues/12010#change-56536
* Author: Yui NARUSE
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
`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:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>