D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8298 - dirEntries special linux file in Home dir
Summary: dirEntries special linux file in Home dir
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
: 11501 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-06-25 11:17 UTC by bioinfornatics
Modified: 2015-06-09 05:15 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bioinfornatics 2012-06-25 11:17:25 UTC
when i use std.file.dirEntries it fail when scanning the home directory(linux) because thay are some special files e.g:
Failed to stat file `./.pulse/b86d160eca2ebd0f61847c4600000013-runtime'

it will be good to have a way to list both files an dir in any case ...



import std.file;
import std.algorithm;
import std.stdio;
import std.path;
import std.array;

void main(){
	DirEntry[] dFiles = array( dirEntries( ".", SpanMode.depth ).filter!( ( a ) =>  a.name.extension == ".d"  ) );
	foreach( d; dFiles )
		writeln( d );
}
Comment 1 Vladimir Panteleev 2012-12-21 21:25:22 UTC
How to create such a special file, in order to reproduce the problem?
Comment 2 Mike Wey 2013-02-16 08:13:38 UTC
The special file as an broken symlink. The Exception is thrown because stat return an error code in that case.

With this pull request:
https://github.com/D-Programming-Language/phobos/pull/1142

I've changed ensureStatDone so it also tries lstat if stat fails as to support broken symlinks in DirEntry.
Comment 3 Mike Wey 2013-11-13 13:15:52 UTC
*** Issue 11501 has been marked as a duplicate of this issue. ***
Comment 4 Timothee Cour 2014-01-07 15:41:11 UTC
Is anything blocking the pull ?
Comment 5 github-bugzilla 2014-01-07 16:23:53 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/eb4d5a0572da733c492ef3b75ff12e74a8f0a522
Fix Issue #8298, Don't throw exceptions on broken symlinks.

Using dirEntries to loop trough all the files/directories in a directory
will curently throw an Exception when encountering an broken symlink.

Whit this change DirEntry will no longer throw an Exception for broken
symlinks, but in that case isDir and isFile will return flase while
isSymlink returns true.

https://github.com/D-Programming-Language/phobos/commit/1d7912c6791bd0a84f67370f4462b922b996701c
Merge pull request #1142 from MikeWey/Issue8298

Fix Issue #8298, Don't throw exceptions on broken symlinks.
Comment 6 Timothee Cour 2014-01-07 16:39:58 UTC
so shall we mark this as FIXED?
Comment 7 Vladimir Panteleev 2014-01-08 01:33:34 UTC
Yes, that pull should have fixed all relevant problems.