FileException when calling getTimes on a DirEntry

Renato renato at athaydes.com
Sun Dec 24 20:00:15 UTC 2023


On Sunday, 24 December 2023 at 15:51:02 UTC, kdevel wrote:
> 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?

Your feedback is really abrasive. What a shame, first time I get 
this kind of attitude in this forum.

>
>> [...]
>> 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.

So, looks like you know what "watch the file system" means then.

Have you ever used notify APIs? Across different operating 
systems?

I have and it's a nightmare of incompatible behaviour, very 
hit-and-miss, you get too many events or no event at all quite 
often.

I know how to implement this without scanning the full tree 
efficiently, which is what I intend to do. In my case, the 
fswatch library would scan the full tree anyway as it's not 
implemented properly for Mac.

Anyway, I didn't ask you for your opinion on this, I asked what 
could be causing an Exception in my code to happen as that was 
quite unexpected.

>
>> ```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.

Have you ever seen a symlink like the one I'd posted?

```
.#hi.txt -> renato at renato.902129:1701726658
```

Does that look like your regular symlink? I don't think it 
does... that's what I was actually trying to find out and hoped 
others here would've seen this weird behaviour before.

But yeah, in the end, I fixed my code by only reacting to files 
and directories.

Merry Christmas to you too.




More information about the Digitalmars-d-learn mailing list