FileException when calling getTimes on a DirEntry

kdevel kdevel at vogtner.de
Sun Dec 24 15:51:02 UTC 2023


On Sunday, 24 December 2023 at 14:19:18 UTC, Renato wrote:
> I was trying to use a library (fswatch) for watching the file 
> system

Watching for what?

> [...]
> My code is really basic, when the directory modified timestamp 
> changes, I list the directory entries with `dirEntries` and 
> then call `dirEntry.getTimes()` on it.

The right way to implement a function which watches for changes 
IN the directory is to use an appropriate notification API, e.g. 
inotify [1]. No one wants software running  on their computer 
which runs in a loop and polls the file system endlessly though 
there is no actual work to do.

> ```d
> [...]
>     entry.getTimes(ac, st);
> ```

You know what symlinks [2] are? You want the timestamps of the 
symlink and not that of the pointed-to file. In C you would use 
`lstat` instead of `stat` for that purpose.

Sometimes symlinks are used to link to objects which are not 
located in the filesystem [3]. Trying to use getTimes on such 
object throws an exception.

[1] https://man7.org/linux/man-pages/man7/inotify.7.html
[2] https://man7.org/linux/man-pages/man7/symlink.7.html
[3] e.g. `ls -laF /proc/self/ns` in Linux.


More information about the Digitalmars-d-learn mailing list