-
-
Notifications
You must be signed in to change notification settings - Fork 740
Fix Issue 16487 - Add function to obtain the available disk space #5776
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
Conversation
Thanks for your pull request and interest in making D better, @jercaianu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#5776" |
Thanks for the comments, I'll shortly look into them as soon as I figure out what's going on with the FreeBSD failure. Also, since we're here, do you think it would be a good idea to add functionality for getFreeDiskSpace or getDiskSpaceCapacity (similar to boost::filesystem) ? Thanks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good so far
just a little change related to version
and it's okay.
I have figured out what's wrong with the FreeBSD test. The question is now, should I add statfs in the runtime, or just assume return 0 for FreeBSD? Thanks, |
Extending the bindings in druntime is almost always welcome as *BSD is vastly lacking behind in terms of maintenance manpower (iirc only one or two of the core people around here use it regularly). |
You throw an exception on failure, so isn't the correct behavior to throw an exception? |
Tagging @andralex since this adds a new public symbol. |
ping @jercaianu This has stalled for far too long. Any chance we can get things moving again? |
@quickfur If statfs would be added, then I can easily finish this. [1] - dlang/druntime#1937 |
std/file.d
Outdated
return GetDiskFreeSpaceExW(path.tempCStringW(), &freeBytesAvailable, null, null); | ||
} (); | ||
enforce(err != 0, | ||
new FileException(text("Cannot get available disk space: ", GetLastError()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at the default constructor of FileException:
version(Windows) this(in char[] name,
uint errno = .GetLastError(),
string file = __FILE__,
size_t line = __LINE__) @safe
{
tl;dr: use cenforce
As this is a new function, it might be worthwhile to check this PR. |
assert(space > 0); | ||
|
||
assertThrown!FileException(getAvailableDiskSpace("ThisFileDoesNotExist123123")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do more tests here. Simple create a directory with deleteme
and write files to it and check the resulting file size (if this varies on Windows, version(Posix)
it).
Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be a bit excessive - we'd be testing the OS primitives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on what you have running on your system, the size could vary a lot.
This may cause such a test to fail at times, despite everything running correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test that the function works for null
and ""
(empty strings) input. See e.g. https://issues.dlang.org/show_bug.cgi?id=14980
This should be alright now |
I would still prefer that we either move this to std.experimental for one release or mark it as unstable in the docs somehow, s.t. we don't accidentally end up releasing something that we can't change anymore (as we used to do in the past), but I won't block this PR further.
@jercaianu what's with the linux32 failure? |
@JackStouffer good to go? |
@andralex Appears unrelated.
|
I won’t be able to review this until late tonight. Please merge without my review if you think this is good to go. |
Why is this stil open? |
Because it fails on FreeBSD. |
@n8sh this probably needs a rebase to pass on circle. |
std/file.d
Outdated
} | ||
else version (Posix) | ||
{ | ||
import std.string : toStringz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function's argument type was changed from string
to const char[]
it should probably use tempCString
instead of toStringz
in the Posix path. toStringz
always allocates if it is given a const char[]
.
Tests are no longer disabled on FreeBSD.
removed redundant line