Why doesn't std.file.exists follow symbolic links?

Jack Applegame japplegame at gmail.com
Fri Jul 2 15:30:43 UTC 2021


On Friday, 2 July 2021 at 15:04:33 UTC, jfondren wrote:
> On Friday, 2 July 2021 at 14:11:22 UTC, Jack Applegame wrote:
>> This is a completely different topic. The above code is just a 
>> demonstration that `std.file.exists` does not follow symbolic 
>> links, and not the real code.
>>
> ...
>>
>> This is also a completely different topic.
>
> The unifying topic is "there is a correct way to work with the
> filesystem, and exists() isn't it, so who cares if languages 
> vary on
> the implementation of a wrong way to work with the filesystem?"

I disagree. In many simple cases, this option is quite acceptable:

```d
void main() {
     try {
         ...
         auto data = readData(file_name);
         ...
     } catch(Exception e) {
         // Fatal error
     }
}

auto readData(string file_name) {
     ...
     if(exists(file_name)) {
         ...
         read_file(file_name);
         ...
     } else {
         ...
         create_file(file_name);
         ...
     }
     ...
}

```

> A naive user of any implementation of exists() is going to have 
> a lot
> more to worry about. A non-naive user of it will be aware of 
> how it is
> implemented.

I am a "naive user" of `exists()` in production and have not 
encountered any problems with it.

Why do people think that any program should be written as if it 
will work on the International Space Station?


More information about the Digitalmars-d mailing list