https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112014-04-26T06:46:31ZRuby Issue Tracking SystemRuby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463242014-04-26T06:46:31Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Is there any files at <code>V:/</code>?</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463262014-04-26T07:02:30Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Backport</strong> changed from <i>2.0.0: UNKNOWN, 2.1: UNKNOWN</i> to <i>2.0.0: DONTNEED, 2.1: DONTNEED</i></li></ul><p>I've tested on 1.9.3-p545, 2.0.0-p451, 2.1.1 and found they are ok.<br>
This problem is only with trunk.</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463272014-04-26T07:22:33Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Usaku NAKAMURA wrote:</p>
<blockquote>
<p>I've tested on 1.9.3-p545, 2.0.0-p451, 2.1.1 and found they are ok.</p>
</blockquote>
<p>‘OK’ means it globs as if it is a real directory but not a symlink?</p>
<blockquote>
<p>This problem is only with trunk.</p>
</blockquote>
<p>It doesn’t glob anything, neither the parent of the symlink, or the target?</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463282014-04-26T07:38:52Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>Hi,</p>
<p>In message "<a href="/issues/9648">[ruby-core:62170]</a> [ruby-trunk - Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windows (Closed)" href="https://bugs.ruby-lang.org/issues/9648">#9648</a>] Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windows"<br>
on Apr.26,2014 16:22:34, <a href="mailto:nobu@ruby-lang.org" class="email">nobu@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>'ok' means it globs as if it is a real directory but not a symlink?</p>
</blockquote>
<p>It's too difficult for me to say it in English.</p>
<p>C:\foo に V:\ へのsymlinkである bar (つまり C:\foo\bar) を作り、<br>
そこに chdir した後で Dir.glob('../*') するわけですが、結果は<br>
期待通り C:\foo の中身(V:\ でなく)を返します。</p>
<blockquote>
<blockquote>
<p>This problem is only with trunk.</p>
</blockquote>
<p>It doesn't glob anything, neither the parent of the symlink, or the target?</p>
</blockquote>
<p>何も返しません。なお、targetである V:\ にはparentが存在しないことは<br>
留意すべき事項かもしれません。<br>
ちなみに、targetを適当なディレクトリ V:\baz に変更して実行すると、<br>
なぜかtrunkでも正しい結果(C:\fooの中身)を返します。</p>
<a name="Regards"></a>
<h2 >Regards,<a href="#Regards" class="wiki-anchor">¶</a></h2>
<p>U.Nakamura <a href="mailto:usa@garbagecollect.jp" class="email">usa@garbagecollect.jp</a></p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463352014-04-28T00:21:41Zh.shirosaki (Hiroshi Shirosaki)h.shirosaki@gmail.com
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>Is there any files at <code>V:/</code>?</p>
</blockquote>
<p>Yes, there are some files and directories at <code>V:/</code>.<br>
If no files and directories exist at <code>V:/</code>, the result is same.</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463472014-04-28T05:31:30Zh.shirosaki (Hiroshi Shirosaki)h.shirosaki@gmail.com
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul><p>If current directory is C:\foo\bar (linked to V:), <code>READDIR</code> of '.' (i.e. <code>FindFirstFile(".\\*", &d)</code>) globs linked directory (V:/), but the result doesn't have '..'.<br>
So we cannot trace parent directory.</p>
<p>Skipping <code>READDIR</code> usage for this case solves the bug.</p>
<pre><code class="patch syntaxhl" data-language="patch"><span class="gh">diff --git a/dir.c b/dir.c
index f456e8b..91a8495 100644
</span><span class="gd">--- a/dir.c
</span><span class="gi">+++ b/dir.c
</span><span class="p">@@ -1397,6 +1397,14 @@</span> glob_helper(
if (exist == NO || isdir == NO) return 0;
<span class="gi">+ if (!(magical || recursive) && (FNM_SYSCASE && plain)) {
+ /* READDIR will not return '..' at a directory which is symbolic linked to
+ a root directory on Windows. We don't use READDIR to get '..'. */
+ struct glob_pattern *p = *beg;
+ if (p && strcmp(p->str, "..") == 0)
+ goto literally;
+ }
+
</span> if (magical || recursive || ((FNM_SYSCASE || HAVE_HFS) && plain)) {
struct dirent *dp;
DIR *dirp;
<span class="err">
</span></code></pre> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463482014-04-28T06:40:04Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Hiroshi Shirosaki wrote:</p>
<blockquote>
<p>If current directory is C:\foo\bar (linked to V:), <code>READDIR</code> of '.' (i.e. <code>FindFirstFile(".\\*", &d)</code>) globs linked directory (V:/), but the result doesn't have '..'.<br>
So we cannot trace parent directory.</p>
</blockquote>
<p>In that case, what should it return?</p>
<ol>
<li>ignores it and globs as if it were not a symlink</li>
<li>matches nothing, since there is no parent directory of a root directory</li>
<li>treat the parent directory same as the root directory, like unixen systems</li>
</ol>
<blockquote>
<p>Skipping <code>READDIR</code> usage for this case solves the bug.</p>
</blockquote>
<p>I'm not sure what is a <em>"bug"</em> yet.</p>
<blockquote>
<pre><code class="patch syntaxhl" data-language="patch"><span class="gi">+ if (!(magical || recursive) && (FNM_SYSCASE && plain)) {
</span></code></pre>
</blockquote>
<p>This "super-root" issue is not common to all case-insensitive systems,<br>
but seems a DOSISH centric probably.</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463492014-04-28T07:02:29Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>In that case, what should it return?</p>
<ol>
<li>ignores it and globs as if it were not a symlink</li>
<li>matches nothing, since there is no parent directory of a root directory</li>
<li>treat the parent directory same as the root directory, like unixen systems</li>
</ol>
</blockquote>
<p>First I think it should returns the directory that the symlink exists (maybe 1 ?),<br>
but now I think it should be 3.</p>
<blockquote>
<blockquote>
<p>Skipping <code>READDIR</code> usage for this case solves the bug.</p>
</blockquote>
<p>I'm not sure what is a <em>"bug"</em> yet.</p>
</blockquote>
<p>I've not tested the patch yet, but I think there are some <em>bug</em>s now.</p>
<ol>
<li>
<code>glob</code> should return the root itself for the parent of the root, like unixen.</li>
<li>
<code>glob</code> should return the parent of the symlinked directory instead of the parent of the symlink, like unixen, too.</li>
</ol> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=463512014-04-28T07:39:28Zh.shirosaki (Hiroshi Shirosaki)h.shirosaki@gmail.com
<ul></ul><p>Usaku NAKAMURA wrote:</p>
<blockquote>
<p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>In that case, what should it return?</p>
<ol>
<li>ignores it and globs as if it were not a symlink</li>
<li>matches nothing, since there is no parent directory of a root directory</li>
<li>treat the parent directory same as the root directory, like unixen systems</li>
</ol>
</blockquote>
<p>First I think it should returns the directory that the symlink exists (maybe 1 ?),<br>
but now I think it should be 3.</p>
</blockquote>
<p>I thought 1. is spec on Windows because old version ruby, <code>dir</code> command and <code>FindFirstFile</code> behavior is same.<br>
I agree to change behavior unixen systems.</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=467632014-05-16T16:49:13Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Unfortunately, it seems to need tools more than expected to deal with symbolic links on Windows.<br>
So I'll fix only the empty result for the meantime.</p> Ruby master - Bug #9648: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windowshttps://bugs.ruby-lang.org/issues/9648?journal_id=467642014-05-16T16:49:38Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset r45965.</p>
<hr>
<p>dir.c: match plain names as-is</p>
<ul>
<li>dir.c (<code>glob_pattern_type</code>): separate names with alphabet but no<br>
magical from plain.</li>
<li>dir.c (<code>glob_helper</code>): match plain names as-is to treat super-root<br>
same as the root. <a href="/issues/9648">[ruby-core:61552]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Dir.glob('../*') shows unexpected result in a symbolic linked directory on Windows (Closed)" href="https://bugs.ruby-lang.org/issues/9648">#9648</a>]</li>
</ul>