Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It should be possible to check exists and isDir/isFile with a single stat call #9606

Open
dlangBugzillaToGithub opened this issue Jun 2, 2013 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

code (@MartinNowak) reported this on 2013-06-02T05:25:01Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=10240

CC List

  • petar.p.kirov
  • razvan.nitu1305

Description

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.
@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2017-10-05T08:28:47Z

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.

@dlangBugzillaToGithub
Copy link
Author

petar.p.kirov commented on 2017-10-05T09:47:27Z

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.

@dlangBugzillaToGithub
Copy link
Author

petar.p.kirov commented on 2017-10-05T09:47:59Z

> while a single function returning a struct would be much more useful...

... and more type-safe.

@dlangBugzillaToGithub
Copy link
Author

petar.p.kirov commented on 2017-10-05T09:54:04Z

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

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants