Thread overview
[Issue 6138] Using dirEntries and chdir() can have unwanted results
Mar 23, 2016
Timothee Cour
Jul 07, 2017
RazvanN
Jul 07, 2017
RazvanN
Jul 07, 2017
Vladimir Panteleev
Jan 29, 2018
Francesco Galla'
Feb 04, 2018
Seb
Feb 10, 2018
Timothee Cour
Mar 16, 2018
Timothee Cour
March 23, 2016
https://issues.dlang.org/show_bug.cgi?id=6138

Timothee Cour <timothee.cour2@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timothee.cour2@gmail.com

--- Comment #1 from Timothee Cour <timothee.cour2@gmail.com> ---
sounds like a bug (and one that could cause harm);
why not have dirEntries call rel2abs ? the cost of this should be dwarfed by
system calls involved in dirEntries

--
October 14, 2016
https://issues.dlang.org/show_bug.cgi?id=6138

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |bootcamp
                 CC|                            |andrei@erdani.com

--
July 07, 2017
https://issues.dlang.org/show_bug.cgi?id=6138

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
Is this still valid? The code seems to have changes significantly (rel2abs doesn't exist anymore) and I cannot reproduce with std.file.absolutePath.

--
July 07, 2017
https://issues.dlang.org/show_bug.cgi?id=6138

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
After analyzing the code I see that dirEntries does not call absolutePath on the path, which in my opinion is a bug. Even though I cannot reproduce the bug, I think a call to absolutePath should definitely be added

--
July 07, 2017
https://issues.dlang.org/show_bug.cgi?id=6138

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
(In reply to RazvanN from comment #3)
> After analyzing the code I see that dirEntries does not call absolutePath on the path, which in my opinion is a bug. Even though I cannot reproduce the bug, I think a call to absolutePath should definitely be added

That might break things.

~ $ mkdir -p a/b/c
~ $ cd a/b/c
~/a/b/c $ touch a
~/a/b/c $ ls
a
~/a/b/c $ ls ~/a/b/c
a
~/a/b/c $ chmod 000 ~/a/b
~/a/b/c $ ls
a
~/a/b/c $ ls ~/a/b/c
ls: cannot access '/home/vladimir/a/b/c': Permission denied
~/a/b/c $

I think the correct solution would be to use fdopendir and openat (on POSIX).

--
January 29, 2018
https://issues.dlang.org/show_bug.cgi?id=6138

Francesco Galla' <francesco.galla3@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |francesco.galla3@gmail.com

--- Comment #5 from Francesco Galla' <francesco.galla3@gmail.com> ---
(In reply to RazvanN from comment #3)
> After analyzing the code I see that dirEntries does not call absolutePath on the path, which in my opinion is a bug. Even though I cannot reproduce the bug, I think a call to absolutePath should definitely be added

I reproduced the bug with the following code:

   foreach (string entry; dirEntries((dir), SpanMode.shallow))
   {
       if (entry.isDir)
       {
            foreach (string subentry; dirEntries(entry, SpanMode.shallow))
            {
                 if (subentry.isDir)
                 {
                     chdir(absolutePath(subentry));
                     writeln (absolutePath(subentry));
                 }
            }
       }
   }

My directory tree is:

.
├── 1
│   └── 2
├── 3
│   ├── 4
│   └── 5
│       └── 6


* The result I obtained was the following:

std.file.FileException@/opt/dmd-2.075/import/std/file.d(1631): ./3: No such
file or directory

* By calling:

foreach (string entry; dirEntries(absolutePath(dir), SpanMode.shallow))

The code was executed correctly. This seems to confirm the need for
dirEntries() to call absolutePath(). Am I mistaken?

--
February 04, 2018
https://issues.dlang.org/show_bug.cgi?id=6138

Seb <greensunny12@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--- Comment #6 from Seb <greensunny12@gmail.com> ---
FYI: Francesco Galla submitted a PR - https://github.com/dlang/phobos/pull/6125

--
February 10, 2018
https://issues.dlang.org/show_bug.cgi?id=6138

--- Comment #7 from Timothee Cour <timothee.cour2@gmail.com> ---
just hit that bug again, but differently:
```
chdir(foo);
auto files=dirEntries(dirSrc, "*.d",
SpanMode.depth).filter!(a=>a.isFile).map!(a=>dir.buildPath(a.name)).array;
```
crashed similarly

--
March 16, 2018
https://issues.dlang.org/show_bug.cgi?id=6138

Timothee Cour <timothee.cour2@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|Windows                     |All
           Severity|normal                      |major

--- Comment #8 from Timothee Cour <timothee.cour2@gmail.com> ---
ping: this is a serious bug
note: i was OSX and the bug was reported on windows originally, so setting to
All

--