Make the DirEntry->FileInfo conversion nothrow.
Avoids listDirectory/iterateDirectory getting interrupted when stumbling over inaccessible files. The `name` field of the returned file info value is always set, so that these files can still be identified.
This commit is contained in:
parent
5b146ab002
commit
8e4adf000f
|
@ -729,22 +729,33 @@ struct DirectoryChange {
|
||||||
|
|
||||||
|
|
||||||
private FileInfo makeFileInfo(DirEntry ent)
|
private FileInfo makeFileInfo(DirEntry ent)
|
||||||
@trusted {
|
@trusted nothrow {
|
||||||
|
import std.algorithm.comparison : among;
|
||||||
|
|
||||||
FileInfo ret;
|
FileInfo ret;
|
||||||
auto fullname = ent.name.endsWith('/') || ent.name.endsWith('\\') ? ent.name[0 .. $-1] : ent.name;
|
if (!ent.name.length) return ret;
|
||||||
|
|
||||||
|
auto fullname = ent.name[$-1].among('/', '\\') ? ent.name[0 .. $-1] : ent.name;
|
||||||
ret.name = baseName(fullname);
|
ret.name = baseName(fullname);
|
||||||
if (ret.name.length == 0) ret.name = fullname;
|
if (ret.name.length == 0) ret.name = fullname;
|
||||||
ret.size = ent.size;
|
|
||||||
ret.timeModified = ent.timeLastModified;
|
try {
|
||||||
version(Windows) ret.timeCreated = ent.timeCreated;
|
ret.isFile = ent.isFile;
|
||||||
else ret.timeCreated = ent.timeLastModified;
|
ret.isDirectory = ent.isDir;
|
||||||
ret.isSymlink = ent.isSymlink;
|
ret.isSymlink = ent.isSymlink;
|
||||||
ret.isDirectory = ent.isDir;
|
ret.timeModified = ent.timeLastModified;
|
||||||
ret.isFile = ent.isFile;
|
version(Windows) ret.timeCreated = ent.timeCreated;
|
||||||
|
else ret.timeCreated = ent.timeLastModified;
|
||||||
|
ret.size = ent.size;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logDebug("Failed to get information for file '%s': %s", fullname, e.msg);
|
||||||
|
}
|
||||||
|
|
||||||
version (Windows) {
|
version (Windows) {
|
||||||
import core.sys.windows.windows : FILE_ATTRIBUTE_HIDDEN;
|
import core.sys.windows.windows : FILE_ATTRIBUTE_HIDDEN;
|
||||||
ret.hidden = (ent.attributes & FILE_ATTRIBUTE_HIDDEN) != 0;
|
ret.hidden = (ent.attributes & FILE_ATTRIBUTE_HIDDEN) != 0;
|
||||||
}
|
}
|
||||||
else ret.hidden = ret.name.startsWith('.');
|
else ret.hidden = ret.name[0] == '.' && ret.name != "." && ret.name != "..";
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue