Path::exists
is not suitable, since its documentation states:
This function will traverse symbolic links to query information about the destination file. In case of broken symbolic links this will return false.
Another option is to use std::fs::symlink_metadata
(docs).
Query the metadata about a file without following symlinks. This function will return an error ... [when]
path
does not exist.
The upside of this is that the returned Metadata
struct contains a FileType
struct (docs), which you can query about whether the path is a plain file, a directory or a symbolic link. This could be useful if the possible outcomes were more than "link exists" and "link does not exist".
std::fs::read_link
seems what you want.
This function will return an error in the following situations, but is not limited to just these cases:
- path is not a symbolic link.
- path does not exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With