TruePath
TruePath copied to clipboard
Check if a file or directory
There should be a method to check if a path represents an existing file or a directory.
Perhaps something like this?
struct LocalPath
{
// …
// null -> not exists
public FileEntryKind? ReadKind() { … }
}
enum FileEntryKind
{
File,
Directory,
// others: Junction, Symlink?
}
I'd like to discuss a few things:
-
Maybe we should introduce an additional type
FileEntryKind.Unknowninstead of nullableFileEntryKindfor theReadKindmethod? In my opinion, this will make the client code more obvious. -
Should
TruePathunderstand that a particular file or directory is aJunctionorSymLink? It seems to me that a library for path processing should not do file processing
Maybe we should introduce an additional type
FileEntryKind.Unknowninstead of nullableFileEntryKindfor theReadKindmethod? In my opinion, this will make the client code more obvious.
Nullable FileEntryKind should signify the absence of a file. We may add Unknown for, well, unknown files. Not for the same cases when there is no file at all.
We may add FileEntryKind.Absent instead, to address the part of your message on null, but I have to say I like null more for that particular purpose. I am open for discussion, though. My motivation is that "no entry" shouldn't be a kind of a file entry. There is no entry, and thus its kind cannot be defined.
Should
TruePathunderstand that a particular file or directory is aJunctionorSymLink? It seems to me that a library for path processing should not do file processing
I believe it should. While you are correct that this somewhat blurs the limits of what TruePath does as a library, kind of a file entry often affects the semantics of file system traversal. So, I would prefer TruePath to be able to distinguish special file entry types such as junctions and symlinks, and expose this knowledge through the API.
File system traversal is something that's in TruePath is in charge of.
Besides, other path management libraries (e.g. java.nio.Path) also expose this knowledge somewhat.
Linking a comment with some proposed behavioral aspects from a related PR: https://github.com/ForNeVeR/TruePath/pull/50#discussion_r1586835863