You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DirEntries() fails on symbolic links to non-existent file. I just had this bug show up.
- I'm making a program that scans all the files in a path and computes their hashes. DirEntries keeps exploding on a random symlink on my hard drive.
- I passed "false" to "followSymlink" in DirEntries(), but it still fails regardless and throws an exception.
- The reason I believe, is that this random spurious file (cmt_drv.la) I have is a symlink to "../cmt_drv.la", and that file doesn't exist.
output:
-----
commandline args:
0 ./dup
1 /home/novous/Downloads/DOWNLOADS BUFFER/xf86-input-cmt/src/.libs/
object.Exception@std/file.d(3219): Failed to stat file `/home/novous/Downloads/DOWNLOADS BUFFER/xf86-input-cmt/src/.libs/cmt_drv.la'
----------------
??:? pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x6cdb691e]
??:? pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x6cd9f9e1]
??:? @trusted void std.file.DirEntry._ensureStatDone() [0x6cd772ee]
??:? @property@safe ulong std.file.DirEntry.size() [0x6cd7713c]
??:? _Dmain [0x6cd58c81]
on github here:
https://github.com/dlang/phobos/blob/master/std/file.d#L3979
It appears "stat" is failing.
This might be key: I'm trying to run sort!("a.size > b.size") on the returned DirEntries, and while sorting it calls .size() which then invokes the stat command.
This program works fine until I ran into this edge-case. I can provide code snippets and clarification as needed.
Thanks,
--Chris
The text was updated successfully, but these errors were encountered:
I don't think there is any problem here. It is correct to throw an exception to a non-existent file getSize.
When traversing files, folders and symlinks, we should judge them and decide whether to do some operations.
import std.file;import std.stdio;string path = "...";foreach (DirEntry e; dirEntries(path, SpanMode.shallow)){ if (e.isSymlink) { string origin = readLink(e.name); if (origin.exists) writeln(origin, ", size: ", e.size); else writeln(origin, " not exists. "); }}
ckatko reported this on 2019-08-05T23:52:22Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=20109
CC List
Description
The text was updated successfully, but these errors were encountered: