Issue 10240 - It should be possible to check exists and isDir/isFile with a single stat call
Summary: It should be possible to check exists and isDir/isFile with a single stat call
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: RazvanN
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-02 05:25 UTC by Martin Nowak
Modified: 2024-12-01 16:17 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2013-06-02 05:25:01 UTC
In std.file the functions isDir, isFile and dirEntry all throw if a path does not exist.
Therefor one needs a separate stat call to test for existence.
Also dirEntry does enforce again that a path exists.
Comment 1 RazvanN 2017-10-05 08:28:47 UTC
There are 2 ways to solve this:

1. Either check that the file or directory exists inside the isDir/isFile functions and return false if the path does not exist or the input string doesn't designate a directory/file. This is troublesome since you have one value for 2 different semantics.

2. Create a function existsAndIsDir/File where you can call stat a single time. This means adding 2 new functions that add no extra functionality for the benefit of a micro-optimization.

In my opinion we should close this as WONTFIX.
Comment 2 ZombineDev 2017-10-05 09:47:27 UTC
I believe the right solution add a function akin to C++17's file_status (http://en.cppreference.com/w/cpp/experimental/fs/file_status) which would return a struct essentially being union of

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364946(v=vs.85).aspx on Windows

and 

http://pubs.opengroup.org/onlinepubs/009695399/functions/stat.html on Posix.

That way users would be to obtain more information in a single call.

Unfortunately we have all kinds of functions defined in https://dlang.org/phobos-prerelease/std_file General, Attributes, Timestamp

while a single function returning a struct would be much more useful.
Comment 3 ZombineDev 2017-10-05 09:47:59 UTC
> while a single function returning a struct would be much more useful...

... and more type-safe.
Comment 4 ZombineDev 2017-10-05 09:54:04 UTC
> I believe the right solution add a function akin to C++17's file_status (http://en.cppreference.com/w/cpp/experimental/fs/file_status)

Here I meant this function:
http://en.cppreference.com/w/cpp/experimental/fs/status

as file_status is a struct.
Comment 5 dlangBugzillaToGithub 2024-12-01 16:17:52 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9606

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB