avoid crashing on files that don't stat, e.g. broken symlinks

This commit is contained in:
John Colvin 2017-08-31 22:56:38 +01:00
parent ecdaa7287f
commit 3617339405
1 changed files with 30 additions and 11 deletions

View File

@ -297,17 +297,36 @@ class FileDialog : Dialog, CustomGridCellAdapter {
else else
resname = "text-plain"; resname = "text-plain";
_fileList.setCellText(0, i, toUTF32(resname)); _fileList.setCellText(0, i, toUTF32(resname));
double size = _entries[i].size; double size = double.nan;
try {
size = _entries[i].size;
} catch (Exception e) {
Log.w(e.msg);
}
import std.math : isNaN;
if (size.isNaN)
sz = "--";
else {
import std.format : format; import std.format : format;
sz = size < 1024 ? to!string(size) ~ " B" : sz = size < 1024 ? to!string(size) ~ " B" :
(size < 1024*1024 ? "%.1f".format(size/1024) ~ " KB" : (size < 1024*1024 ? "%.1f".format(size/1024) ~ " KB" :
(size < 1024*1024*1024 ? "%.1f".format(size/(1024*1024)) ~ " MB" : (size < 1024*1024*1024 ? "%.1f".format(size/(1024*1024)) ~ " MB" :
"%.1f".format(size/(1024*1024*1024)) ~ " GB")); "%.1f".format(size/(1024*1024*1024)) ~ " GB"));
import std.datetime; }
SysTime ts = _entries[i].timeLastModified; import std.datetime : SysTime;
//string timeString = "%04d.%02d.%02d %02d:%02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second); import std.typecons : Nullable;
string timeString = "%04d.%02d.%02d %02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute); Nullable!SysTime ts;
date = timeString; try {
ts = _entries[i].timeLastModified;
} catch (Exception e) {
Log.w(e.msg);
}
if (ts.isNull)
date = "----.--.-- --:--";
else {
//date = "%04d.%02d.%02d %02d:%02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
date = "%04d.%02d.%02d %02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute);
}
} }
_fileList.setCellText(2, i, toUTF32(sz)); _fileList.setCellText(2, i, toUTF32(sz));
_fileList.setCellText(3, i, toUTF32(date)); _fileList.setCellText(3, i, toUTF32(date));