Thread overview | |||||
---|---|---|---|---|---|
|
May 19, 2014 Can't call isDir on linux on const object | ||||
---|---|---|---|---|
| ||||
The same code works on windows DMD 1.65. But on linux: delold.d(54): Error: mutable method std.file.DirEntry.isDir is not callable using a const object [code] bool printFile(in DirEntry dirEntry, in Duration age, Options options) { immutable string type = dirEntry.isDir ? "directory" : dirEntry.isFile ? "file" : "unknown"; if (!options.beQuiet) writefln("%s %s, %s is %s days old", type, dirEntry.name, dirEntry.timeLastModified, age.total!"days"); return true; } [/code] |
May 19, 2014 Re: Can't call isDir on linux on const object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Spacen | On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote:
> The same code works on windows DMD 1.65. But on linux:
It's because of caching. isDir on Linux calls a function with this comment:
/++
This is to support lazy evaluation, because doing stat's is
expensive and not always needed.
Try both stat and lstat for isFile and isDir
to detect broken symlinks.
+/
void _ensureStatOrLStatDone()
Simple solution is to just take a plain DirEntry instead of "in DirEntry" so it isn't const.
|
May 19, 2014 Re: Can't call isDir on linux on const object | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 19 May 2014 at 20:18:40 UTC, Adam D. Ruppe wrote:
> On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote:
>> The same code works on windows DMD 1.65. But on linux:
>
> It's because of caching. isDir on Linux calls a function with this comment:
>
> /++
> This is to support lazy evaluation, because doing stat's is
> expensive and not always needed.
>
> Try both stat and lstat for isFile and isDir
> to detect broken symlinks.
> +/
> void _ensureStatOrLStatDone()
>
>
> Simple solution is to just take a plain DirEntry instead of "in DirEntry" so it isn't const.
Thanks Adam. Nice and portable then.
|
Copyright © 1999-2021 by the D Language Foundation